Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8719)

Unified Diff: chrome/renderer/extensions/extension_process_bindings.cc

Issue 208020: Change the view mode when switching between moles and toolstrips, and (Closed)
Patch Set: build system workarounds Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/extensions/extension_process_bindings.h ('k') | chrome/renderer/render_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/extensions/extension_process_bindings.cc
diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc
index 7a9d0ac0ae0c2c98787e5bbce3a1ba9e1f8a230c..0fc9438080062cb6cfab2e16f4375cea81c0c7da 100644
--- a/chrome/renderer/extensions/extension_process_bindings.cc
+++ b/chrome/renderer/extensions/extension_process_bindings.cc
@@ -28,6 +28,7 @@ using bindings_utils::GetPendingRequestMap;
using bindings_utils::PendingRequest;
using bindings_utils::PendingRequestMap;
using bindings_utils::ExtensionBase;
+using WebKit::WebFrame;
namespace {
@@ -119,6 +120,25 @@ class ExtensionImpl : public ExtensionBase {
return v8::String::New(GetStringResource<IDR_EXTENSION_API_JSON>());
}
+ // Returns true is |type| "isa" |match|.
+ static bool ViewTypeMatches(ViewType::Type type, ViewType::Type match) {
+ if (type == match)
+ return true;
+
+ // INVALID means match all.
+ if (match == ViewType::INVALID)
+ return true;
+
+ // TODO(erikkay) for now, special case mole as a type of toolstrip.
+ // Perhaps this isn't the right long-term thing to do.
+ if (match == ViewType::EXTENSION_TOOLSTRIP &&
+ type == ViewType::EXTENSION_MOLE) {
+ return true;
+ }
+
+ return false;
+ }
+
static v8::Handle<v8::Value> GetExtensionViews(const v8::Arguments& args) {
if (args.Length() != 2)
return v8::Undefined();
@@ -135,6 +155,8 @@ class ExtensionImpl : public ExtensionBase {
ViewType::Type view_type = ViewType::INVALID;
if (view_type_string == "TOOLSTRIP") {
view_type = ViewType::EXTENSION_TOOLSTRIP;
+ } else if (view_type_string == "MOLE") {
+ view_type = ViewType::EXTENSION_MOLE;
} else if (view_type_string == "BACKGROUND") {
view_type = ViewType::EXTENSION_BACKGROUND_PAGE;
} else if (view_type_string == "TAB") {
@@ -154,7 +176,7 @@ class ExtensionImpl : public ExtensionBase {
std::set<RenderView* >::iterator it =
render_view_set_pointer->render_view_set_.begin();
for (; it != render_view_set_pointer->render_view_set_.end(); ++it) {
- if (view_type != ViewType::INVALID && (*it)->view_type() != view_type)
+ if (!ViewTypeMatches((*it)->view_type(), view_type))
continue;
GURL url = (*it)->webview()->GetMainFrame()->url();
@@ -396,3 +418,25 @@ v8::Handle<v8::Value>
return v8::ThrowException(v8::Exception::Error(
v8::String::New(error_msg.c_str())));
}
+
+// static
+void ExtensionProcessBindings::SetViewType(WebView* view,
+ ViewType::Type type) {
+ DCHECK(type == ViewType::EXTENSION_MOLE ||
+ type == ViewType::EXTENSION_TOOLSTRIP);
+ const char* type_str;
+ if (type == ViewType::EXTENSION_MOLE)
+ type_str = "mole";
+ else if (type == ViewType::EXTENSION_TOOLSTRIP)
+ type_str = "toolstrip";
+ else
+ return;
+
+ v8::HandleScope handle_scope;
+ WebFrame* frame = view->GetMainFrame();
+ v8::Local<v8::Context> context = frame->mainWorldScriptContext();
+ v8::Handle<v8::Value> argv[1];
+ argv[0] = v8::String::New(type_str);
+ bindings_utils::CallFunctionInContext(context, "setViewType",
+ arraysize(argv), argv);
+}
« no previous file with comments | « chrome/renderer/extensions/extension_process_bindings.h ('k') | chrome/renderer/render_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698