Bug 1264701 - combine url utils to rep-utils.js; r?linclark
MozReview-Commit-ID: Gdtg6Nf1Spj
--- a/devtools/client/shared/components/reps/document.js
+++ b/devtools/client/shared/components/reps/document.js
@@ -6,19 +6,18 @@
"use strict";
// Make this available to both AMD and CJS environments
define(function (require, exports, module) {
// ReactJS
const React = require("devtools/client/shared/vendor/react");
// Reps
- const { createFactories, isGrip } = require("./rep-utils");
+ const { createFactories, isGrip, getFileName } = require("./rep-utils");
const { ObjectBox } = createFactories(require("./object-box"));
- const { getFileName } = require("./url");
// Shortcuts
const { span } = React.DOM;
/**
* Renders DOM document object.
*/
let Document = React.createClass({
--- a/devtools/client/shared/components/reps/moz.build
+++ b/devtools/client/shared/components/reps/moz.build
@@ -26,11 +26,10 @@ DevToolsModules(
'regexp.js',
'rep-utils.js',
'rep.js',
'reps.css',
'string.js',
'stylesheet.js',
'text-node.js',
'undefined.js',
- 'url.js',
'window.js',
)
--- a/devtools/client/shared/components/reps/rep-utils.js
+++ b/devtools/client/shared/components/reps/rep-utils.js
@@ -1,8 +1,9 @@
+/* globals URLSearchParams */
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
@@ -68,14 +69,82 @@ define(function (require, exports, modul
if (text.length > limit) {
return text.substr(0, Math.ceil(halfLimit)) + alternativeText +
text.substr(text.length - Math.floor(halfLimit));
}
return text;
}
+ function parseURLParams(url) {
+ url = new URL(url);
+ return parseURLEncodedText(url.searchParams);
+ }
+
+ function parseURLEncodedText(text) {
+ let params = [];
+
+ // In case the text is empty just return the empty parameters
+ if (text == "") {
+ return params;
+ }
+
+ let searchParams = new URLSearchParams(text);
+ let entries = [...searchParams.entries()];
+ return entries.map(entry => {
+ return {
+ name: entry[0],
+ value: entry[1]
+ };
+ });
+ }
+
+ function getFileName(url) {
+ let split = splitURLBase(url);
+ return split.name;
+ }
+
+ function splitURLBase(url) {
+ if (!isDataURL(url)) {
+ return splitURLTrue(url);
+ }
+ return {};
+ }
+
+ function isDataURL(url) {
+ return (url && url.substr(0, 5) == "data:");
+ }
+
+ function splitURLTrue(url) {
+ const reSplitFile = /(.*?):\/{2,3}([^\/]*)(.*?)([^\/]*?)($|\?.*)/;
+ let m = reSplitFile.exec(url);
+
+ if (!m) {
+ return {
+ name: url,
+ path: url
+ };
+ } else if (m[4] == "" && m[5] == "") {
+ return {
+ protocol: m[1],
+ domain: m[2],
+ path: m[3],
+ name: m[3] != "/" ? m[3] : m[2]
+ };
+ }
+
+ return {
+ protocol: m[1],
+ domain: m[2],
+ path: m[2] + m[3],
+ name: m[4] + m[5]
+ };
+ }
+
// Exports from this module
exports.createFactories = createFactories;
exports.isGrip = isGrip;
exports.cropString = cropString;
exports.cropMultipleLines = cropMultipleLines;
+ exports.parseURLParams = parseURLParams;
+ exports.parseURLEncodedText = parseURLEncodedText;
+ exports.getFileName = getFileName;
});
--- a/devtools/client/shared/components/reps/stylesheet.js
+++ b/devtools/client/shared/components/reps/stylesheet.js
@@ -6,19 +6,18 @@
"use strict";
// Make this available to both AMD and CJS environments
define(function (require, exports, module) {
// ReactJS
const React = require("devtools/client/shared/vendor/react");
// Reps
- const { createFactories, isGrip } = require("./rep-utils");
+ const { createFactories, isGrip, getFileName } = require("./rep-utils");
const { ObjectBox } = createFactories(require("./object-box"));
- const { getFileName } = require("./url");
// Shortcuts
const DOM = React.DOM;
/**
* Renders a grip representing CSSStyleSheet
*/
let StyleSheet = React.createClass({
deleted file mode 100644
--- a/devtools/client/shared/components/reps/url.js
+++ /dev/null
@@ -1,81 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
-/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-/* global URLSearchParams */
-
-"use strict";
-
-// Make this available to both AMD and CJS environments
-define(function (require, exports, module) {
- function parseURLParams(url) {
- url = new URL(url);
- return parseURLEncodedText(url.searchParams);
- }
-
- function parseURLEncodedText(text) {
- let params = [];
-
- // In case the text is empty just return the empty parameters
- if (text == "") {
- return params;
- }
-
- let searchParams = new URLSearchParams(text);
- let entries = [...searchParams.entries()];
- return entries.map(entry => {
- return {
- name: entry[0],
- value: entry[1]
- };
- });
- }
-
- function getFileName(url) {
- let split = splitURLBase(url);
- return split.name;
- }
-
- function splitURLBase(url) {
- if (!isDataURL(url)) {
- return splitURLTrue(url);
- }
- return {};
- }
-
- function isDataURL(url) {
- return (url && url.substr(0, 5) == "data:");
- }
-
- function splitURLTrue(url) {
- const reSplitFile = /(.*?):\/{2,3}([^\/]*)(.*?)([^\/]*?)($|\?.*)/;
- let m = reSplitFile.exec(url);
-
- if (!m) {
- return {
- name: url,
- path: url
- };
- } else if (m[4] == "" && m[5] == "") {
- return {
- protocol: m[1],
- domain: m[2],
- path: m[3],
- name: m[3] != "/" ? m[3] : m[2]
- };
- }
-
- return {
- protocol: m[1],
- domain: m[2],
- path: m[2] + m[3],
- name: m[4] + m[5]
- };
- }
-
- // Exports from this module
- exports.parseURLParams = parseURLParams;
- exports.parseURLEncodedText = parseURLEncodedText;
- exports.getFileName = getFileName;
-});
--- a/devtools/client/webconsole/net/components/post-tab.js
+++ b/devtools/client/webconsole/net/components/post-tab.js
@@ -1,18 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const React = require("devtools/client/shared/vendor/react");
// Reps
-const { createFactories } = require("devtools/client/shared/components/reps/rep-utils");
-const { parseURLEncodedText } = require("devtools/client/shared/components/reps/url");
+const { createFactories, parseURLEncodedText } = require("devtools/client/shared/components/reps/rep-utils");
const TreeView = React.createFactory(require("devtools/client/shared/components/tree/tree-view"));
const { Rep } = createFactories(require("devtools/client/shared/components/reps/rep"));
// Network
const NetInfoParams = React.createFactory(require("./net-info-params"));
const NetInfoGroupList = React.createFactory(require("./net-info-group-list"));
const Spinner = React.createFactory(require("./spinner"));
const SizeLimit = React.createFactory(require("./size-limit"));
--- a/devtools/client/webconsole/net/net-request.js
+++ b/devtools/client/webconsole/net/net-request.js
@@ -3,17 +3,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
// React
const React = require("devtools/client/shared/vendor/react");
const ReactDOM = require("devtools/client/shared/vendor/react-dom");
// Reps
-const { parseURLParams } = require("devtools/client/shared/components/reps/url");
+const { parseURLParams } = require("devtools/client/shared/components/reps/rep-utils");
// Network
const { cancelEvent, isLeftClick } = require("./utils/events");
const NetInfoBody = React.createFactory(require("./components/net-info-body"));
const DataProvider = require("./data-provider");
// Constants
const XHTML_NS = "http://www.w3.org/1999/xhtml";