diff options
author | erikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-19 19:31:51 +0000 |
---|---|---|
committer | erikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-19 19:31:51 +0000 |
commit | 078b3461fa0eee0bcf9e4b43f8b7a3171f9e0018 (patch) | |
tree | 6292b5fc4583430029fccafe4e16907c7dbd2cad /chrome/renderer/extensions | |
parent | 2291d04b0d127ca1b31c4326f9297253e4399d2b (diff) | |
download | chromium_src-078b3461fa0eee0bcf9e4b43f8b7a3171f9e0018.zip chromium_src-078b3461fa0eee0bcf9e4b43f8b7a3171f9e0018.tar.gz chromium_src-078b3461fa0eee0bcf9e4b43f8b7a3171f9e0018.tar.bz2 |
Change the view mode when switching between moles and toolstrips, and
propogate this into the class of the document element so that it's
possible to use CSS rules to control the display of your toolstrip/mole.
BUG=21939,15494
TEST=run the Mappy extension and verify it can open and close
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=26635
Review URL: http://codereview.chromium.org/208020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26654 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/extensions')
-rw-r--r-- | chrome/renderer/extensions/extension_process_bindings.cc | 46 | ||||
-rw-r--r-- | chrome/renderer/extensions/extension_process_bindings.h | 9 |
2 files changed, 53 insertions, 2 deletions
diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc index 7a9d0ac..0fc9438 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); +} diff --git a/chrome/renderer/extensions/extension_process_bindings.h b/chrome/renderer/extensions/extension_process_bindings.h index bea3e91..1777658 100644 --- a/chrome/renderer/extensions/extension_process_bindings.h +++ b/chrome/renderer/extensions/extension_process_bindings.h @@ -11,10 +11,12 @@ #include <string> #include <vector> +#include "chrome/common/view_types.h" #include "v8/include/v8.h" class GURL; class URLPattern; +class WebView; class ExtensionProcessBindings { public: @@ -36,7 +38,7 @@ class ExtensionProcessBindings { // Sets the host permissions for a particular extension. static void SetHostPermissions(const GURL& extension_url, - const std::vector<URLPattern>& permissions); + const std::vector<URLPattern>& permissions); // Check if the extension in the currently running context has permission to // access the given extension function. Must be called with a valid V8 @@ -47,6 +49,11 @@ class ExtensionProcessBindings { // denied. Must be called with a valid V8 context in scope. static v8::Handle<v8::Value> ThrowPermissionDeniedException( const std::string& function_name); + + // For EXTENSION_* |type| values, adds/replaces a special class name on to + // the document element (e.g. "extension_toolstrip", "extension_mole") so + // that the page can use CSS rules to control its display appropriately. + static void SetViewType(WebView* view, ViewType::Type type); }; #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_PROCESS_BINDINGS_H_ |