summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrginda@chromium.org <rginda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-11 23:34:05 +0000
committerrginda@chromium.org <rginda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-11 23:34:05 +0000
commitebff6542dbf613ce685a28b4f2c1648895750731 (patch)
treef7334d940705091d845e9503acaccdd1fcd71f09
parent73f6329544798bba5f67e135f6b0680a38f3f827 (diff)
downloadchromium_src-ebff6542dbf613ce685a28b4f2c1648895750731.zip
chromium_src-ebff6542dbf613ce685a28b4f2c1648895750731.tar.gz
chromium_src-ebff6542dbf613ce685a28b4f2c1648895750731.tar.bz2
Add cr.commandLine object, use it to disable network changes when bwsi
Review URL: http://codereview.chromium.org/3412014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62211 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/dom_ui/options/options_ui.cc17
-rw-r--r--chrome/browser/dom_ui/options/options_ui.h1
-rw-r--r--chrome/browser/resources/options.html1
-rw-r--r--chrome/browser/resources/options/chromeos_internet_network_element.js8
-rw-r--r--chrome/browser/resources/shared/js/cr/command_line.js93
-rw-r--r--chrome/browser/resources/shared_resources.grd2
6 files changed, 121 insertions, 1 deletions
diff --git a/chrome/browser/dom_ui/options/options_ui.cc b/chrome/browser/dom_ui/options/options_ui.cc
index e08ba10..4d4cc48 100644
--- a/chrome/browser/dom_ui/options/options_ui.cc
+++ b/chrome/browser/dom_ui/options/options_ui.cc
@@ -8,6 +8,7 @@
#include "app/resource_bundle.h"
#include "base/callback.h"
+#include "base/command_line.h"
#include "base/message_loop.h"
#include "base/singleton.h"
#include "base/string_piece.h"
@@ -33,6 +34,7 @@
#include "chrome/browser/dom_ui/options/search_engine_manager_handler.h"
#include "chrome/browser/dom_ui/options/sync_options_handler.h"
#include "chrome/browser/metrics/user_metrics.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
@@ -208,6 +210,21 @@ OptionsUI::~OptionsUI() {
}
}
+// Override.
+void OptionsUI::RenderViewCreated(RenderViewHost* render_view_host) {
+ std::string command_line_string;
+
+#if defined(OS_WIN)
+ std::wstring wstr = CommandLine::ForCurrentProcess()->command_line_string();
+ command_line_string = WideToASCII(wstr);
+#else
+ command_line_string = CommandLine::ForCurrentProcess()->command_line_string();
+#endif
+
+ render_view_host->SetDOMUIProperty("commandLineString", command_line_string);
+ DOMUI::RenderViewCreated(render_view_host);
+}
+
// static
RefCountedMemory* OptionsUI::GetFaviconResourceBytes() {
return ResourceBundle::GetSharedInstance().
diff --git a/chrome/browser/dom_ui/options/options_ui.h b/chrome/browser/dom_ui/options/options_ui.h
index 7b49ebd..4f9bf6c 100644
--- a/chrome/browser/dom_ui/options/options_ui.h
+++ b/chrome/browser/dom_ui/options/options_ui.h
@@ -83,6 +83,7 @@ class OptionsUI : public DOMUI {
virtual ~OptionsUI();
static RefCountedMemory* GetFaviconResourceBytes();
+ void RenderViewCreated(RenderViewHost* render_view_host);
void InitializeHandlers();
diff --git a/chrome/browser/resources/options.html b/chrome/browser/resources/options.html
index 9bdcf1d..eddc265 100644
--- a/chrome/browser/resources/options.html
+++ b/chrome/browser/resources/options.html
@@ -42,6 +42,7 @@
<script src="chrome://resources/css/tree.css.js"></script>
<script src="chrome://resources/js/cr.js"></script>
+<script src="chrome://resources/js/cr/command_line.js"></script>
<script src="chrome://resources/js/cr/event_target.js"></script>
<script src="chrome://resources/js/cr/ui.js"></script>
<script src="chrome://resources/js/cr/ui/array_data_model.js"></script>
diff --git a/chrome/browser/resources/options/chromeos_internet_network_element.js b/chrome/browser/resources/options/chromeos_internet_network_element.js
index e90e319..142fccd2 100644
--- a/chrome/browser/resources/options/chromeos_internet_network_element.js
+++ b/chrome/browser/resources/options/chromeos_internet_network_element.js
@@ -170,7 +170,13 @@ cr.define('options.internet', function() {
}
} else {
// forget button
- buttonsDiv.appendChild(this.createButton_('forget_button', 'forget'));
+ var button = this.createButton_('forget_button', 'forget');
+ if (cr.commandLine.options['--bwsi']) {
+ // no disabling of networks while bwsi.
+ button.disabled = true;
+ }
+
+ buttonsDiv.appendChild(button);
}
this.appendChild(buttonsDiv);
},
diff --git a/chrome/browser/resources/shared/js/cr/command_line.js b/chrome/browser/resources/shared/js/cr/command_line.js
new file mode 100644
index 0000000..2333b51
--- /dev/null
+++ b/chrome/browser/resources/shared/js/cr/command_line.js
@@ -0,0 +1,93 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview CommandLine class, parses out individual options from a
+ * command line string.
+ *
+ * This file depends on chrome.commandLineString, which is only set if your
+ * DOM UI explicitly sets it. The DOM UI based options dialog does this from
+ * OptionsUI::RenderViewCreated, in options_ui.cc.
+ */
+
+cr.define('cr', function() {
+ /**
+ * Class to reperesent command line options passed to chrome.
+ *
+ * Instances of this class will have the following properties:
+ * executable: The name of the executable used to start chrome
+ *
+ * options: An object containing the named arguments. If the argument
+ * was assigned a value, such as --foo=bar, then options['--foo'] will be
+ * set to 'bar'. If the argument was not assigned a value, such as
+ * --enable-foo, then options['--enable-foo'] will be set to true.
+ *
+ * looseArguments: An array of arguments that were not associated with
+ * argument names.
+ *
+ * Note that the Chromium code that computes the command line string
+ * has a bug that strips quotes from command lines, so you can't really
+ * trust looseArguments or any argument that might contain spaces until
+ * http://code.google.com/p/chromium/issues/detail?id=56684 is fixed.
+ *
+ * @param {string} commandLineString The command line string to parse.
+ */
+ function CommandLine(commandLineString) {
+ this.commandLineString_ = commandLineString;
+ this.parseOptions_(commandLineString.split(/\s+/));
+ }
+
+ /**
+ * Return the command line as a single string.
+ */
+ CommandLine.prototype.toString = function() {
+ return this.commandLineString_;
+ };
+
+ /**
+ * Parse the array of command line options into this.executable, this.options,
+ * and this.looseArguments.
+ *
+ * @param {Array} ary The list of command line arguments. The first argument
+ * must be the executable name. Named command line arguments must start
+ * with two dashes, and may optionally be assigned a value as in
+ * --argument-name=value.
+ */
+ CommandLine.prototype.parseOptions_ = function(ary) {
+ this.executable = ary.shift();
+ this.options = {};
+ this.looseArguments = [];
+
+ for (var i = 0; i < ary.length; i++) {
+ var arg = ary[i];
+
+ if (arg.substr(0, 2) == '--') {
+ var pos = arg.indexOf('=');
+ if (pos > 0) {
+ // Argument has a value: --argument-name=value
+ this.options[arg.substr(0, pos)] = arg.substr(pos + 1);
+ } else {
+ // Argument is a flag: --some-flag
+ this.options[arg] = true;
+ }
+ } else {
+ // Argument doesn't start with '--'.
+ this.looseArguments.push(arg);
+ }
+ }
+ };
+
+ var commandLine = null;
+ if (chrome && chrome.commandLineString) {
+ commandLine = new CommandLine(chrome.commandLineString);
+ } else {
+ console.warn('chrome.commandLineString is not present. Not initializing ' +
+ 'cr.commandLine');
+ }
+
+ return {
+ CommandLine: CommandLine,
+ commandLine: commandLine
+ };
+});
diff --git a/chrome/browser/resources/shared_resources.grd b/chrome/browser/resources/shared_resources.grd
index 18dc93a..0005019 100644
--- a/chrome/browser/resources/shared_resources.grd
+++ b/chrome/browser/resources/shared_resources.grd
@@ -26,6 +26,8 @@ without changes to the corresponding grd file. paaaae -->
file="shared/css/tree.css.js" type="BINDATA" />
<include name="IDR_SHARED_JS_CR"
file="shared/js/cr.js" type="BINDATA" />
+ <include name="IDR_SHARED_JS_CR_COMMAND_LINE"
+ file="shared/js/cr/command_line.js" type="BINDATA" />
<include name="IDR_SHARED_JS_CR_EVENT_TARGET"
file="shared/js/cr/event_target.js" type="BINDATA" />
<include name="IDR_SHARED_JS_CR_LINK_CONTROLLER"