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 156 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 |