OLD | NEW |
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/dispatcher.h" | 5 #include "chrome/renderer/extensions/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/debug/alias.h" | 9 #include "base/debug/alias.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 } | 545 } |
546 | 546 |
547 void Dispatcher::OnSetChannel(int channel) { | 547 void Dispatcher::OnSetChannel(int channel) { |
548 Feature::SetCurrentChannel( | 548 Feature::SetCurrentChannel( |
549 static_cast<chrome::VersionInfo::Channel>(channel)); | 549 static_cast<chrome::VersionInfo::Channel>(channel)); |
550 } | 550 } |
551 | 551 |
552 void Dispatcher::OnMessageInvoke(const std::string& extension_id, | 552 void Dispatcher::OnMessageInvoke(const std::string& extension_id, |
553 const std::string& function_name, | 553 const std::string& function_name, |
554 const base::ListValue& args, | 554 const base::ListValue& args, |
555 const GURL& event_url, | |
556 bool user_gesture) { | 555 bool user_gesture) { |
557 scoped_ptr<WebScopedUserGesture> web_user_gesture; | 556 scoped_ptr<WebScopedUserGesture> web_user_gesture; |
558 if (user_gesture) { | 557 if (user_gesture) { |
559 web_user_gesture.reset(new WebScopedUserGesture); | 558 web_user_gesture.reset(new WebScopedUserGesture); |
560 } | 559 } |
561 | 560 |
562 v8_context_set_.DispatchChromeHiddenMethod( | 561 v8_context_set_.DispatchChromeHiddenMethod( |
563 extension_id, function_name, args, NULL, event_url); | 562 extension_id, function_name, args, NULL); |
564 | 563 |
565 // Reset the idle handler each time there's any activity like event or message | 564 // Reset the idle handler each time there's any activity like event or message |
566 // dispatch, for which Invoke is the chokepoint. | 565 // dispatch, for which Invoke is the chokepoint. |
567 if (is_extension_process_) { | 566 if (is_extension_process_) { |
568 RenderThread::Get()->ScheduleIdleHandler( | 567 RenderThread::Get()->ScheduleIdleHandler( |
569 kInitialExtensionIdleHandlerDelayMs); | 568 kInitialExtensionIdleHandlerDelayMs); |
570 } | 569 } |
571 | 570 |
572 // Tell the browser process when an event has been dispatched with a lazy | 571 // Tell the browser process when an event has been dispatched with a lazy |
573 // background page active. | 572 // background page active. |
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1352 void Dispatcher::OnSuspend(const std::string& extension_id) { | 1351 void Dispatcher::OnSuspend(const std::string& extension_id) { |
1353 // Dispatch the suspend event. This doesn't go through the standard event | 1352 // Dispatch the suspend event. This doesn't go through the standard event |
1354 // dispatch machinery because it requires special handling. We need to let | 1353 // dispatch machinery because it requires special handling. We need to let |
1355 // the browser know when we are starting and stopping the event dispatch, so | 1354 // the browser know when we are starting and stopping the event dispatch, so |
1356 // that it still considers the extension idle despite any activity the suspend | 1355 // that it still considers the extension idle despite any activity the suspend |
1357 // event creates. | 1356 // event creates. |
1358 base::ListValue args; | 1357 base::ListValue args; |
1359 args.Set(0, new base::StringValue(kOnSuspendEvent)); | 1358 args.Set(0, new base::StringValue(kOnSuspendEvent)); |
1360 args.Set(1, new base::ListValue()); | 1359 args.Set(1, new base::ListValue()); |
1361 v8_context_set_.DispatchChromeHiddenMethod( | 1360 v8_context_set_.DispatchChromeHiddenMethod( |
1362 extension_id, kEventDispatchFunction, args, NULL, GURL()); | 1361 extension_id, kEventDispatchFunction, args, NULL); |
1363 | 1362 |
1364 RenderThread::Get()->Send(new ExtensionHostMsg_SuspendAck(extension_id)); | 1363 RenderThread::Get()->Send(new ExtensionHostMsg_SuspendAck(extension_id)); |
1365 } | 1364 } |
1366 | 1365 |
1367 void Dispatcher::OnCancelSuspend(const std::string& extension_id) { | 1366 void Dispatcher::OnCancelSuspend(const std::string& extension_id) { |
1368 base::ListValue args; | 1367 base::ListValue args; |
1369 args.Set(0, new base::StringValue(kOnSuspendCanceledEvent)); | 1368 args.Set(0, new base::StringValue(kOnSuspendCanceledEvent)); |
1370 args.Set(1, new base::ListValue()); | 1369 args.Set(1, new base::ListValue()); |
1371 v8_context_set_.DispatchChromeHiddenMethod( | 1370 v8_context_set_.DispatchChromeHiddenMethod( |
1372 extension_id, kEventDispatchFunction, args, NULL, GURL()); | 1371 extension_id, kEventDispatchFunction, args, NULL); |
1373 } | 1372 } |
1374 | 1373 |
1375 Feature::Context Dispatcher::ClassifyJavaScriptContext( | 1374 Feature::Context Dispatcher::ClassifyJavaScriptContext( |
1376 const std::string& extension_id, | 1375 const std::string& extension_id, |
1377 int extension_group, | 1376 int extension_group, |
1378 const ExtensionURLInfo& url_info) { | 1377 const ExtensionURLInfo& url_info) { |
1379 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) { | 1378 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) { |
1380 return extensions_.Contains(extension_id) ? | 1379 return extensions_.Contains(extension_id) ? |
1381 Feature::CONTENT_SCRIPT_CONTEXT : Feature::UNSPECIFIED_CONTEXT; | 1380 Feature::CONTENT_SCRIPT_CONTEXT : Feature::UNSPECIFIED_CONTEXT; |
1382 } | 1381 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 1458 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
1460 v8::ThrowException( | 1459 v8::ThrowException( |
1461 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1460 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
1462 return false; | 1461 return false; |
1463 } | 1462 } |
1464 | 1463 |
1465 return true; | 1464 return true; |
1466 } | 1465 } |
1467 | 1466 |
1468 } // namespace extensions | 1467 } // namespace extensions |
OLD | NEW |