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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 using WebKit::WebView; | 76 using WebKit::WebView; |
77 using content::RenderThread; | 77 using content::RenderThread; |
78 using content::RenderView; | 78 using content::RenderView; |
79 | 79 |
80 namespace extensions { | 80 namespace extensions { |
81 | 81 |
82 namespace { | 82 namespace { |
83 | 83 |
84 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; | 84 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; |
85 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; | 85 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; |
86 static const char kEventDispatchFunction[] = "Event.dispatchJSON"; | 86 static const char kEventDispatchFunction[] = "Event.dispatchEvent"; |
87 static const char kOnUnloadEvent[] = "runtime.onSuspend"; | 87 static const char kOnUnloadEvent[] = "runtime.onSuspend"; |
88 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; | 88 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; |
89 | 89 |
90 class ChromeHiddenNativeHandler : public NativeHandler { | 90 class ChromeHiddenNativeHandler : public NativeHandler { |
91 public: | 91 public: |
92 ChromeHiddenNativeHandler() { | 92 ChromeHiddenNativeHandler() { |
93 RouteFunction("GetChromeHidden", | 93 RouteFunction("GetChromeHidden", |
94 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden, | 94 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden, |
95 base::Unretained(this))); | 95 base::Unretained(this))); |
96 } | 96 } |
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 } | 1016 } |
1017 | 1017 |
1018 void Dispatcher::OnUnload(const std::string& extension_id) { | 1018 void Dispatcher::OnUnload(const std::string& extension_id) { |
1019 // Dispatch the unload event. This doesn't go through the standard event | 1019 // Dispatch the unload event. This doesn't go through the standard event |
1020 // dispatch machinery because it requires special handling. We need to let | 1020 // dispatch machinery because it requires special handling. We need to let |
1021 // the browser know when we are starting and stopping the event dispatch, so | 1021 // the browser know when we are starting and stopping the event dispatch, so |
1022 // that it still considers the extension idle despite any activity the unload | 1022 // that it still considers the extension idle despite any activity the unload |
1023 // event creates. | 1023 // event creates. |
1024 ListValue args; | 1024 ListValue args; |
1025 args.Set(0, Value::CreateStringValue(kOnUnloadEvent)); | 1025 args.Set(0, Value::CreateStringValue(kOnUnloadEvent)); |
1026 args.Set(1, Value::CreateStringValue("[]")); | 1026 args.Set(1, new ListValue()); |
1027 v8_context_set_.DispatchChromeHiddenMethod( | 1027 v8_context_set_.DispatchChromeHiddenMethod( |
1028 extension_id, kEventDispatchFunction, args, NULL, GURL()); | 1028 extension_id, kEventDispatchFunction, args, NULL, GURL()); |
1029 | 1029 |
1030 RenderThread::Get()->Send(new ExtensionHostMsg_UnloadAck(extension_id)); | 1030 RenderThread::Get()->Send(new ExtensionHostMsg_UnloadAck(extension_id)); |
1031 } | 1031 } |
1032 | 1032 |
1033 void Dispatcher::OnCancelUnload(const std::string& extension_id) { | 1033 void Dispatcher::OnCancelUnload(const std::string& extension_id) { |
1034 ListValue args; | 1034 ListValue args; |
1035 args.Set(0, Value::CreateStringValue(kOnSuspendCanceledEvent)); | 1035 args.Set(0, Value::CreateStringValue(kOnSuspendCanceledEvent)); |
1036 args.Set(1, Value::CreateStringValue("[]")); | 1036 args.Set(1, new ListValue()); |
1037 v8_context_set_.DispatchChromeHiddenMethod( | 1037 v8_context_set_.DispatchChromeHiddenMethod( |
1038 extension_id, kEventDispatchFunction, args, NULL, GURL()); | 1038 extension_id, kEventDispatchFunction, args, NULL, GURL()); |
1039 } | 1039 } |
1040 | 1040 |
1041 Feature::Context Dispatcher::ClassifyJavaScriptContext( | 1041 Feature::Context Dispatcher::ClassifyJavaScriptContext( |
1042 const std::string& extension_id, | 1042 const std::string& extension_id, |
1043 int extension_group, | 1043 int extension_group, |
1044 const ExtensionURLInfo& url_info) { | 1044 const ExtensionURLInfo& url_info) { |
1045 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) { | 1045 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) { |
1046 return extensions_.Contains(extension_id) ? | 1046 return extensions_.Contains(extension_id) ? |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 // we should abort. | 1128 // we should abort. |
1129 WebKit::WebFrame* frame = context->web_frame(); | 1129 WebKit::WebFrame* frame = context->web_frame(); |
1130 ExtensionURLInfo url_info(frame->document().securityOrigin(), | 1130 ExtensionURLInfo url_info(frame->document().securityOrigin(), |
1131 UserScriptSlave::GetDataSourceURLForFrame(frame)); | 1131 UserScriptSlave::GetDataSourceURLForFrame(frame)); |
1132 CHECK(!extensions_.IsSandboxedPage(url_info)); | 1132 CHECK(!extensions_.IsSandboxedPage(url_info)); |
1133 | 1133 |
1134 return true; | 1134 return true; |
1135 } | 1135 } |
1136 | 1136 |
1137 } // namespace extensions | 1137 } // namespace extensions |
OLD | NEW |