| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/renderer/runtime_custom_bindings.h" | 5 #include "extensions/renderer/runtime_custom_bindings.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 CHECK(context()->extension()); | 100 CHECK(context()->extension()); |
| 101 | 101 |
| 102 std::unique_ptr<content::V8ValueConverter> converter( | 102 std::unique_ptr<content::V8ValueConverter> converter( |
| 103 content::V8ValueConverter::create()); | 103 content::V8ValueConverter::create()); |
| 104 args.GetReturnValue().Set(converter->ToV8Value( | 104 args.GetReturnValue().Set(converter->ToV8Value( |
| 105 context()->extension()->manifest()->value(), context()->v8_context())); | 105 context()->extension()->manifest()->value(), context()->v8_context())); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void RuntimeCustomBindings::GetExtensionViews( | 108 void RuntimeCustomBindings::GetExtensionViews( |
| 109 const v8::FunctionCallbackInfo<v8::Value>& args) { | 109 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 110 CHECK_EQ(args.Length(), 2); | 110 CHECK_EQ(args.Length(), 3); |
| 111 CHECK(args[0]->IsInt32()); | 111 CHECK(args[0]->IsInt32()); |
| 112 CHECK(args[1]->IsString()); | 112 CHECK(args[1]->IsString()); |
| 113 CHECK(args[2]->IsInt32()); |
| 113 | 114 |
| 114 // |browser_window_id| == extension_misc::kUnknownWindowId means getting | 115 // |browser_window_id| == extension_misc::kUnknownWindowId means getting |
| 115 // all views for the current extension. | 116 // all views for the current extension. |
| 116 int browser_window_id = args[0]->Int32Value(); | 117 int browser_window_id = args[0]->Int32Value(); |
| 118 int tab_id = args[2]->Int32Value(); |
| 117 | 119 |
| 118 std::string view_type_string = | 120 std::string view_type_string = |
| 119 base::ToUpperASCII(*v8::String::Utf8Value(args[1])); | 121 base::ToUpperASCII(*v8::String::Utf8Value(args[1])); |
| 120 // |view_type| == VIEW_TYPE_INVALID means getting any type of | 122 // |view_type| == VIEW_TYPE_INVALID means getting any type of |
| 121 // views. | 123 // views. |
| 122 ViewType view_type = VIEW_TYPE_INVALID; | 124 ViewType view_type = VIEW_TYPE_INVALID; |
| 123 if (view_type_string == kViewTypeBackgroundPage) { | 125 if (view_type_string == kViewTypeBackgroundPage) { |
| 124 view_type = VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; | 126 view_type = VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; |
| 125 } else if (view_type_string == kViewTypeTabContents) { | 127 } else if (view_type_string == kViewTypeTabContents) { |
| 126 view_type = VIEW_TYPE_TAB_CONTENTS; | 128 view_type = VIEW_TYPE_TAB_CONTENTS; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 137 } else { | 139 } else { |
| 138 CHECK_EQ(view_type_string, kViewTypeAll); | 140 CHECK_EQ(view_type_string, kViewTypeAll); |
| 139 } | 141 } |
| 140 | 142 |
| 141 const std::string& extension_id = context()->GetExtensionID(); | 143 const std::string& extension_id = context()->GetExtensionID(); |
| 142 if (extension_id.empty()) | 144 if (extension_id.empty()) |
| 143 return; | 145 return; |
| 144 | 146 |
| 145 std::vector<content::RenderFrame*> frames = | 147 std::vector<content::RenderFrame*> frames = |
| 146 ExtensionFrameHelper::GetExtensionFrames(extension_id, browser_window_id, | 148 ExtensionFrameHelper::GetExtensionFrames(extension_id, browser_window_id, |
| 147 view_type); | 149 tab_id, view_type); |
| 148 v8::Local<v8::Context> v8_context = args.GetIsolate()->GetCurrentContext(); | 150 v8::Local<v8::Context> v8_context = args.GetIsolate()->GetCurrentContext(); |
| 149 v8::Local<v8::Array> v8_views = v8::Array::New(args.GetIsolate()); | 151 v8::Local<v8::Array> v8_views = v8::Array::New(args.GetIsolate()); |
| 150 int v8_index = 0; | 152 int v8_index = 0; |
| 151 for (content::RenderFrame* frame : frames) { | 153 for (content::RenderFrame* frame : frames) { |
| 152 // We filter out iframes here. GetExtensionViews should only return the | 154 // We filter out iframes here. GetExtensionViews should only return the |
| 153 // main views, not any subframes. (Returning subframes can cause broken | 155 // main views, not any subframes. (Returning subframes can cause broken |
| 154 // behavior by treating an app window's iframe as its main frame, and maybe | 156 // behavior by treating an app window's iframe as its main frame, and maybe |
| 155 // other nastiness). | 157 // other nastiness). |
| 156 blink::WebFrame* web_frame = frame->GetWebFrame(); | 158 blink::WebFrame* web_frame = frame->GetWebFrame(); |
| 157 if (web_frame->top() != web_frame) | 159 if (web_frame->top() != web_frame) |
| 158 continue; | 160 continue; |
| 159 | 161 |
| 160 if (!blink::WebFrame::scriptCanAccess(web_frame)) | 162 if (!blink::WebFrame::scriptCanAccess(web_frame)) |
| 161 continue; | 163 continue; |
| 162 | 164 |
| 163 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext(); | 165 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext(); |
| 164 if (!context.IsEmpty()) { | 166 if (!context.IsEmpty()) { |
| 165 v8::Local<v8::Value> window = context->Global(); | 167 v8::Local<v8::Value> window = context->Global(); |
| 166 CHECK(!window.IsEmpty()); | 168 CHECK(!window.IsEmpty()); |
| 167 v8::Maybe<bool> maybe = | 169 v8::Maybe<bool> maybe = |
| 168 v8_views->CreateDataProperty(v8_context, v8_index++, window); | 170 v8_views->CreateDataProperty(v8_context, v8_index++, window); |
| 169 CHECK(maybe.IsJust() && maybe.FromJust()); | 171 CHECK(maybe.IsJust() && maybe.FromJust()); |
| 170 } | 172 } |
| 171 } | 173 } |
| 172 | 174 |
| 173 args.GetReturnValue().Set(v8_views); | 175 args.GetReturnValue().Set(v8_views); |
| 174 } | 176 } |
| 175 | 177 |
| 176 } // namespace extensions | 178 } // namespace extensions |
| OLD | NEW |