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

Side by Side Diff: extensions/renderer/extension_frame_helper.cc

Issue 2886923002: [extension SW]: Support event listener registration and event dispatching. (Closed)
Patch Set: removed debug logs Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/extension_frame_helper.h" 5 #include "extensions/renderer/extension_frame_helper.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/timer/elapsed_timer.h" 9 #include "base/timer/elapsed_timer.h"
10 #include "content/public/child/worker_thread.h"
10 #include "content/public/renderer/render_frame.h" 11 #include "content/public/renderer/render_frame.h"
11 #include "extensions/common/api/messaging/message.h" 12 #include "extensions/common/api/messaging/message.h"
12 #include "extensions/common/api/messaging/port_id.h" 13 #include "extensions/common/api/messaging/port_id.h"
13 #include "extensions/common/constants.h" 14 #include "extensions/common/constants.h"
14 #include "extensions/common/extension_messages.h" 15 #include "extensions/common/extension_messages.h"
15 #include "extensions/common/manifest_handlers/background_info.h" 16 #include "extensions/common/manifest_handlers/background_info.h"
16 #include "extensions/renderer/console.h" 17 #include "extensions/renderer/console.h"
17 #include "extensions/renderer/content_watcher.h" 18 #include "extensions/renderer/content_watcher.h"
18 #include "extensions/renderer/dispatcher.h" 19 #include "extensions/renderer/dispatcher.h"
19 #include "extensions/renderer/messaging_bindings.h" 20 #include "extensions/renderer/messaging_bindings.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 142
142 // static 143 // static
143 bool ExtensionFrameHelper::IsContextForEventPage(const ScriptContext* context) { 144 bool ExtensionFrameHelper::IsContextForEventPage(const ScriptContext* context) {
144 content::RenderFrame* render_frame = context->GetRenderFrame(); 145 content::RenderFrame* render_frame = context->GetRenderFrame();
145 return context->extension() && render_frame && 146 return context->extension() && render_frame &&
146 BackgroundInfo::HasLazyBackgroundPage(context->extension()) && 147 BackgroundInfo::HasLazyBackgroundPage(context->extension()) &&
147 ExtensionFrameHelper::Get(render_frame)->view_type() == 148 ExtensionFrameHelper::Get(render_frame)->view_type() ==
148 VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; 149 VIEW_TYPE_EXTENSION_BACKGROUND_PAGE;
149 } 150 }
150 151
152 bool ExtensionFrameHelper::IsContextForSW(const ScriptContext& context) {
Devlin 2017/05/24 17:58:25 We already have context_type() on ScriptContext; d
lazyboy 2017/05/25 01:33:43 context_type() should be fine, thanks. Done.
153 if (content::WorkerThread::GetCurrentId() != 0) {
154 DCHECK(context.GetRenderFrame() == nullptr);
155 return true;
156 }
157 return false;
158 }
159
151 void ExtensionFrameHelper::DidCreateDocumentElement() { 160 void ExtensionFrameHelper::DidCreateDocumentElement() {
152 did_create_current_document_element_ = true; 161 did_create_current_document_element_ = true;
153 extension_dispatcher_->DidCreateDocumentElement( 162 extension_dispatcher_->DidCreateDocumentElement(
154 render_frame()->GetWebFrame()); 163 render_frame()->GetWebFrame());
155 } 164 }
156 165
157 void ExtensionFrameHelper::DidCreateNewDocument() { 166 void ExtensionFrameHelper::DidCreateNewDocument() {
158 did_create_current_document_element_ = false; 167 did_create_current_document_element_ = false;
159 } 168 }
160 169
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 const base::ListValue& args) { 338 const base::ListValue& args) {
330 extension_dispatcher_->InvokeModuleSystemMethod( 339 extension_dispatcher_->InvokeModuleSystemMethod(
331 render_frame(), extension_id, module_name, function_name, args); 340 render_frame(), extension_id, module_name, function_name, args);
332 } 341 }
333 342
334 void ExtensionFrameHelper::OnDestruct() { 343 void ExtensionFrameHelper::OnDestruct() {
335 delete this; 344 delete this;
336 } 345 }
337 346
338 } // namespace extensions 347 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698