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

Side by Side Diff: chrome/renderer/extensions/extension_dispatcher.cc

Issue 10114015: Fix bug where transient pages would miss events dispatched while it was (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/extension_dispatcher.h" 5 #include "chrome/renderer/extensions/extension_dispatcher.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/string_piece.h" 10 #include "base/string_piece.h"
(...skipping 27 matching lines...) Expand all
38 #include "chrome/renderer/extensions/set_icon_natives.h" 38 #include "chrome/renderer/extensions/set_icon_natives.h"
39 #include "chrome/renderer/extensions/tabs_custom_bindings.h" 39 #include "chrome/renderer/extensions/tabs_custom_bindings.h"
40 #include "chrome/renderer/extensions/tts_custom_bindings.h" 40 #include "chrome/renderer/extensions/tts_custom_bindings.h"
41 #include "chrome/renderer/extensions/user_script_slave.h" 41 #include "chrome/renderer/extensions/user_script_slave.h"
42 #include "chrome/renderer/extensions/web_request_custom_bindings.h" 42 #include "chrome/renderer/extensions/web_request_custom_bindings.h"
43 #include "chrome/renderer/extensions/webstore_bindings.h" 43 #include "chrome/renderer/extensions/webstore_bindings.h"
44 #include "chrome/renderer/module_system.h" 44 #include "chrome/renderer/module_system.h"
45 #include "chrome/renderer/native_handler.h" 45 #include "chrome/renderer/native_handler.h"
46 #include "chrome/renderer/resource_bundle_source_map.h" 46 #include "chrome/renderer/resource_bundle_source_map.h"
47 #include "content/public/renderer/render_thread.h" 47 #include "content/public/renderer/render_thread.h"
48 #include "content/public/renderer/render_view.h"
48 #include "grit/renderer_resources.h" 49 #include "grit/renderer_resources.h"
49 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" 50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 51 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
51 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 52 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
52 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedUserGesture. h" 53 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedUserGesture. h"
53 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" 54 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
54 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 55 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
55 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" 56 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
56 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h" 57 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h"
57 #include "ui/base/resource/resource_bundle.h" 58 #include "ui/base/resource/resource_bundle.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 base::Bind(&LazyBackgroundPageNativeHandler::IncrementKeepaliveCount, 135 base::Bind(&LazyBackgroundPageNativeHandler::IncrementKeepaliveCount,
135 base::Unretained(this))); 136 base::Unretained(this)));
136 RouteFunction("DecrementKeepaliveCount", 137 RouteFunction("DecrementKeepaliveCount",
137 base::Bind(&LazyBackgroundPageNativeHandler::DecrementKeepaliveCount, 138 base::Bind(&LazyBackgroundPageNativeHandler::DecrementKeepaliveCount,
138 base::Unretained(this))); 139 base::Unretained(this)));
139 } 140 }
140 141
141 v8::Handle<v8::Value> IncrementKeepaliveCount(const v8::Arguments& args) { 142 v8::Handle<v8::Value> IncrementKeepaliveCount(const v8::Arguments& args) {
142 ChromeV8Context* context = 143 ChromeV8Context* context =
143 extension_dispatcher()->v8_context_set().GetCurrent(); 144 extension_dispatcher()->v8_context_set().GetCurrent();
144 if (IsCurrentContextLazyBackgroundPage(context->extension())) { 145 if (!context)
145 content::RenderThread::Get()->Send( 146 return v8::Undefined();
146 new ExtensionHostMsg_IncrementLazyKeepaliveCount( 147 content::RenderView* render_view = context->GetRenderView();
147 context->extension()->id())); 148 if (IsContextLazyBackgroundPage(render_view, context->extension())) {
149 render_view->Send(new ExtensionHostMsg_IncrementLazyKeepaliveCount(
150 render_view->GetRoutingID()));
148 } 151 }
149 return v8::Undefined(); 152 return v8::Undefined();
150 } 153 }
151 154
152 v8::Handle<v8::Value> DecrementKeepaliveCount(const v8::Arguments& args) { 155 v8::Handle<v8::Value> DecrementKeepaliveCount(const v8::Arguments& args) {
153 ChromeV8Context* context = 156 ChromeV8Context* context =
154 extension_dispatcher()->v8_context_set().GetCurrent(); 157 extension_dispatcher()->v8_context_set().GetCurrent();
155 if (IsCurrentContextLazyBackgroundPage(context->extension())) { 158 if (!context)
156 content::RenderThread::Get()->Send( 159 return v8::Undefined();
157 new ExtensionHostMsg_DecrementLazyKeepaliveCount( 160 content::RenderView* render_view = context->GetRenderView();
158 context->extension()->id())); 161 if (IsContextLazyBackgroundPage(render_view, context->extension())) {
162 render_view->Send(new ExtensionHostMsg_DecrementLazyKeepaliveCount(
163 render_view->GetRoutingID()));
159 } 164 }
160 return v8::Undefined(); 165 return v8::Undefined();
161 } 166 }
162 167
163 private: 168 private:
164 bool IsCurrentContextLazyBackgroundPage(const Extension* extension) { 169 bool IsContextLazyBackgroundPage(content::RenderView* render_view,
165 content::RenderView* render_view = GetCurrentRenderView(); 170 const Extension* extension) {
166 if (!render_view) 171 if (!render_view)
167 return false; 172 return false;
168 173
169 ExtensionHelper* helper = ExtensionHelper::Get(render_view); 174 ExtensionHelper* helper = ExtensionHelper::Get(render_view);
170 return (extension && extension->has_lazy_background_page() && 175 return (extension && extension->has_lazy_background_page() &&
171 helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); 176 helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
172 } 177 }
173 }; 178 };
174 179
175 void InstallAppBindings(ModuleSystem* module_system, 180 void InstallAppBindings(ModuleSystem* module_system,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 v8_context_set_.DispatchChromeHiddenMethod( 303 v8_context_set_.DispatchChromeHiddenMethod(
299 extension_id, function_name, args, NULL, event_url); 304 extension_id, function_name, args, NULL, event_url);
300 305
301 // Reset the idle handler each time there's any activity like event or message 306 // Reset the idle handler each time there's any activity like event or message
302 // dispatch, for which Invoke is the chokepoint. 307 // dispatch, for which Invoke is the chokepoint.
303 if (is_extension_process_) { 308 if (is_extension_process_) {
304 RenderThread::Get()->ScheduleIdleHandler( 309 RenderThread::Get()->ScheduleIdleHandler(
305 kInitialExtensionIdleHandlerDelayMs); 310 kInitialExtensionIdleHandlerDelayMs);
306 } 311 }
307 312
313 // Tell the browser process when an event has been dispatched with a lazy
314 // background page active.
308 const Extension* extension = extensions_.GetByID(extension_id); 315 const Extension* extension = extensions_.GetByID(extension_id);
309 // Tell the browser process that the event is dispatched and we're idle.
310 if (extension && extension->has_lazy_background_page() && 316 if (extension && extension->has_lazy_background_page() &&
311 function_name == kEventDispatchFunction) { 317 function_name == kEventDispatchFunction) {
312 RenderThread::Get()->Send( 318 content::RenderView* background_view =
313 new ExtensionHostMsg_ExtensionEventAck(extension_id)); 319 ExtensionHelper::GetBackgroundPage(extension_id);
320 if (background_view) {
321 background_view->Send(new ExtensionHostMsg_EventAck(
322 background_view->GetRoutingID()));
323 }
314 } 324 }
315 } 325 }
316 326
317 void ExtensionDispatcher::OnDispatchOnConnect( 327 void ExtensionDispatcher::OnDispatchOnConnect(
318 int target_port_id, 328 int target_port_id,
319 const std::string& channel_name, 329 const std::string& channel_name,
320 const std::string& tab_json, 330 const std::string& tab_json,
321 const std::string& source_extension_id, 331 const std::string& source_extension_id,
322 const std::string& target_extension_id) { 332 const std::string& target_extension_id) {
323 MiscellaneousBindings::DispatchOnConnect( 333 MiscellaneousBindings::DispatchOnConnect(
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 static const char kMessage[] = 892 static const char kMessage[] =
883 "%s can only be used in an extension process."; 893 "%s can only be used in an extension process.";
884 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); 894 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str());
885 v8::ThrowException( 895 v8::ThrowException(
886 v8::Exception::Error(v8::String::New(error_msg.c_str()))); 896 v8::Exception::Error(v8::String::New(error_msg.c_str())));
887 return false; 897 return false;
888 } 898 }
889 899
890 return true; 900 return true;
891 } 901 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698