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

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

Issue 164458: Land http://codereview.chromium.org/159067: (Closed)
Patch Set: undo docs Created 11 years, 4 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/bindings_utils.cc ('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 cf0f3444403e9aa6069fc605db49c4e80ae603a4..cb22bce0033fad0c79a44eee3f5df869cb54a7bb 100644
--- a/chrome/renderer/extensions/extension_process_bindings.cc
+++ b/chrome/renderer/extensions/extension_process_bindings.cc
@@ -92,8 +92,8 @@ class ExtensionImpl : public ExtensionBase {
v8::Handle<v8::String> name) {
if (name->Equals(v8::String::New("GetExtensionAPIDefinition"))) {
return v8::FunctionTemplate::New(GetExtensionAPIDefinition);
- } else if (name->Equals(v8::String::New("GetViews"))) {
- return v8::FunctionTemplate::New(GetViews);
+ } else if (name->Equals(v8::String::New("GetExtensionViews"))) {
+ return v8::FunctionTemplate::New(GetExtensionViews);
} else if (name->Equals(v8::String::New("GetNextRequestId"))) {
return v8::FunctionTemplate::New(GetNextRequestId);
} else if (name->Equals(v8::String::New("OpenChannelToTab"))) {
@@ -113,22 +113,66 @@ class ExtensionImpl : public ExtensionBase {
return v8::String::New(GetStringResource<IDR_EXTENSION_API_JSON>());
}
- static v8::Handle<v8::Value> GetViews(const v8::Arguments& args) {
- std::string extension_id = ExtensionIdForCurrentContext();
+ static v8::Handle<v8::Value> GetExtensionViews(const v8::Arguments& args) {
+ if (args.Length() != 2)
+ return v8::Undefined();
+
+ if (!args[0]->IsInt32() || !args[1]->IsString())
+ return v8::Undefined();
- ContextList contexts =
- bindings_utils::GetContextsForExtension(extension_id);
- DCHECK(contexts.size() > 0);
+ // |browser_window_id| == -1 means getting views attached to any browser
+ // window.
+ int browser_window_id = args[0]->Int32Value();
+
+ std::string view_type_string = *v8::String::Utf8Value(args[1]->ToString());
+ // |view_type| == ViewType::INVALID means getting any type of views.
+ ViewType::Type view_type = ViewType::INVALID;
+ if (view_type_string == "TOOLSTRIP") {
+ view_type = ViewType::EXTENSION_TOOLSTRIP;
+ } else if (view_type_string == "BACKGROUND") {
+ view_type = ViewType::EXTENSION_BACKGROUND_PAGE;
+ } else if (view_type_string == "TAB") {
+ view_type = ViewType::TAB_CONTENTS;
+ } else if (view_type_string != "ALL") {
+ return v8::Undefined();
+ }
- v8::Local<v8::Array> views = v8::Array::New(contexts.size());
+ v8::Local<v8::Array> views = v8::Array::New();
int index = 0;
- ContextList::const_iterator it = contexts.begin();
- for (; it != contexts.end(); ++it) {
- v8::Local<v8::Value> window = (*it)->context->Global()->Get(
- v8::String::New("window"));
- DCHECK(!window.IsEmpty());
- views->Set(v8::Integer::New(index), window);
- index++;
+ RenderView::RenderViewSet* render_view_set_pointer =
+ Singleton<RenderView::RenderViewSet>::get();
+ DCHECK(render_view_set_pointer->render_view_set_.size() > 0);
+
+ v8::Local<v8::Value> window;
+ std::string current_extension_id = ExtensionIdForCurrentContext();
+ 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)
+ continue;
+
+ GURL url = (*it)->webview()->GetMainFrame()->url();
+ if (!url.SchemeIs(chrome::kExtensionScheme))
+ continue;
+ std::string extension_id = url.host();
+ if (extension_id != current_extension_id)
+ continue;
+
+ if (browser_window_id != -1 &&
+ (*it)->browser_window_id() != browser_window_id) {
+ continue;
+ }
+
+ v8::Local<v8::Context> context =
+ (*it)->webview()->GetMainFrame()->mainWorldScriptContext();
+ if (!context.IsEmpty()) {
+ v8::Local<v8::Value> window = context->Global();
+ DCHECK(!window.IsEmpty());
+ views->Set(v8::Integer::New(index), window);
+ index++;
+ if (view_type == ViewType::EXTENSION_BACKGROUND_PAGE)
+ break;
+ }
}
return views;
}
« no previous file with comments | « chrome/renderer/extensions/bindings_utils.cc ('k') | chrome/renderer/render_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698