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 "extensions/browser/api/declarative/declarative_api.h" | 5 #include "extensions/browser/api/declarative/declarative_api.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 namespace AddRules = extensions::core_api::events::Event::AddRules; | 27 namespace AddRules = extensions::core_api::events::Event::AddRules; |
28 namespace GetRules = extensions::core_api::events::Event::GetRules; | 28 namespace GetRules = extensions::core_api::events::Event::GetRules; |
29 namespace RemoveRules = extensions::core_api::events::Event::RemoveRules; | 29 namespace RemoveRules = extensions::core_api::events::Event::RemoveRules; |
30 | 30 |
31 | 31 |
32 namespace extensions { | 32 namespace extensions { |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 const char kWebRequest[] = "declarativeWebRequest."; | 36 const char kWebRequest[] = "declarativeWebRequest."; |
37 const char kDeclarativeContent[] = "declarativeContent."; | |
37 const char kWebViewExpectedError[] = "Webview event with Webview ID expected."; | 38 const char kWebViewExpectedError[] = "Webview event with Webview ID expected."; |
38 | 39 |
39 bool IsWebViewEvent(const std::string& event_name) { | 40 bool IsWebViewEvent(const std::string& event_name) { |
40 // Sample event names: | 41 // Sample event names: |
41 // webViewInternal.onRequest. | 42 // webViewInternal.onRequest. |
42 // webViewInternal.onMessage. | 43 // webViewInternal.onMessage. |
43 return event_name.compare(0, | 44 return event_name.compare(0, |
44 strlen(webview::kWebViewEventPrefix), | 45 strlen(webview::kWebViewEventPrefix), |
45 webview::kWebViewEventPrefix) == 0; | 46 webview::kWebViewEventPrefix) == 0; |
46 } | 47 } |
47 | 48 |
48 std::string GetWebRequestEventName(const std::string& event_name) { | 49 std::string GetWebRequestEventName(const std::string& event_name) { |
49 std::string web_request_event_name(event_name); | 50 std::string web_request_event_name(event_name); |
50 if (IsWebViewEvent(web_request_event_name)) { | 51 if (IsWebViewEvent(web_request_event_name)) { |
51 web_request_event_name.replace( | 52 if (web_request_event_name.find(kDeclarativeContent) == std::string::npos) { |
52 0, strlen(webview::kWebViewEventPrefix), kWebRequest); | 53 web_request_event_name.replace( |
54 0, strlen(webview::kWebViewEventPrefix), kWebRequest); | |
55 } else { | |
56 web_request_event_name.replace( | |
57 0, strlen(webview::kWebViewEventPrefix), ""); | |
58 } | |
53 } | 59 } |
54 return web_request_event_name; | 60 return web_request_event_name; |
55 } | 61 } |
56 | 62 |
57 void ConvertBinaryDictionaryValuesToBase64(base::DictionaryValue* dict); | 63 void ConvertBinaryDictionaryValuesToBase64(base::DictionaryValue* dict); |
58 | 64 |
59 // Encodes |binary| as base64 and returns a new StringValue populated with the | 65 // Encodes |binary| as base64 and returns a new StringValue populated with the |
60 // encoded string. | 66 // encoded string. |
61 scoped_ptr<base::StringValue> ConvertBinaryToBase64(base::BinaryValue* binary) { | 67 scoped_ptr<base::StringValue> ConvertBinaryToBase64(base::BinaryValue* binary) { |
62 std::string binary_data = std::string(binary->GetBuffer(), binary->GetSize()); | 68 std::string binary_data = std::string(binary->GetBuffer(), binary->GetSize()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 std::string event_name; | 145 std::string event_name; |
140 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &event_name)); | 146 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &event_name)); |
141 | 147 |
142 int web_view_instance_id = 0; | 148 int web_view_instance_id = 0; |
143 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &web_view_instance_id)); | 149 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &web_view_instance_id)); |
144 int embedder_process_id = render_view_host()->GetProcess()->GetID(); | 150 int embedder_process_id = render_view_host()->GetProcess()->GetID(); |
145 | 151 |
146 bool has_web_view = web_view_instance_id != 0; | 152 bool has_web_view = web_view_instance_id != 0; |
147 if (has_web_view != IsWebViewEvent(event_name)) | 153 if (has_web_view != IsWebViewEvent(event_name)) |
148 EXTENSION_FUNCTION_ERROR(kWebViewExpectedError); | 154 EXTENSION_FUNCTION_ERROR(kWebViewExpectedError); |
149 event_name = GetWebRequestEventName(event_name); | 155 event_name = GetWebRequestEventName(event_name); |
Fady Samuel
2014/12/10 15:56:47
Are the three lines above necessary? Can we clean
Xi Han
2014/12/11 16:40:04
Done.
| |
150 | 156 |
151 // If we are not operating on a particular <webview>, then the key is 0. | 157 // If we are not operating on a particular <webview>, then the key is 0. |
152 int rules_registry_id = RulesRegistryService::kDefaultRulesRegistryID; | 158 int rules_registry_id = RulesRegistryService::kDefaultRulesRegistryID; |
153 if (has_web_view) { | 159 if (has_web_view) { |
154 rules_registry_id = WebViewGuest::GetOrGenerateRulesRegistryID( | 160 rules_registry_id = WebViewGuest::GetOrGenerateRulesRegistryID( |
155 embedder_process_id, web_view_instance_id, browser_context()); | 161 embedder_process_id, web_view_instance_id, browser_context()); |
156 } | 162 } |
157 | 163 |
158 // The following call will return a NULL pointer for apps_shell, but should | 164 // The following call will return a NULL pointer for apps_shell, but should |
159 // never be called there anyways. | 165 // never be called there anyways. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 } else { | 225 } else { |
220 rules_registry_->GetAllRules(extension_id(), &rules); | 226 rules_registry_->GetAllRules(extension_id(), &rules); |
221 } | 227 } |
222 | 228 |
223 results_ = GetRules::Results::Create(rules); | 229 results_ = GetRules::Results::Create(rules); |
224 | 230 |
225 return true; | 231 return true; |
226 } | 232 } |
227 | 233 |
228 } // namespace extensions | 234 } // namespace extensions |
OLD | NEW |