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 "content/public/browser/web_ui_message_handler.h" | 5 #include "content/public/browser/web_ui_message_handler.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 void WebUIMessageHandler::AllowJavascript() { | 14 void WebUIMessageHandler::AllowJavascript() { |
15 if (javascript_allowed_) | 15 if (javascript_allowed_) |
16 return; | 16 return; |
17 | 17 |
18 javascript_allowed_ = true; | 18 javascript_allowed_ = true; |
19 CHECK(IsJavascriptAllowed()); | 19 CHECK(IsJavascriptAllowed()); |
20 | 20 |
21 OnJavascriptAllowed(); | 21 OnJavascriptAllowed(); |
22 } | 22 } |
23 | 23 |
| 24 void WebUIMessageHandler::DisallowJavascript() { |
| 25 if (!javascript_allowed_) |
| 26 return; |
| 27 |
| 28 javascript_allowed_ = false; |
| 29 DCHECK(!IsJavascriptAllowed()); |
| 30 |
| 31 OnJavascriptDisallowed(); |
| 32 } |
| 33 |
24 bool WebUIMessageHandler::IsJavascriptAllowed() const { | 34 bool WebUIMessageHandler::IsJavascriptAllowed() const { |
25 return javascript_allowed_ && web_ui() && web_ui()->CanCallJavascript(); | 35 return javascript_allowed_ && web_ui() && web_ui()->CanCallJavascript(); |
26 } | 36 } |
27 | 37 |
28 bool WebUIMessageHandler::ExtractIntegerValue(const base::ListValue* value, | 38 bool WebUIMessageHandler::ExtractIntegerValue(const base::ListValue* value, |
29 int* out_int) { | 39 int* out_int) { |
30 std::string string_value; | 40 std::string string_value; |
31 if (value->GetString(0, &string_value)) | 41 if (value->GetString(0, &string_value)) |
32 return base::StringToInt(string_value, out_int); | 42 return base::StringToInt(string_value, out_int); |
33 double double_value; | 43 double double_value; |
(...skipping 19 matching lines...) Expand all Loading... |
53 base::string16 WebUIMessageHandler::ExtractStringValue( | 63 base::string16 WebUIMessageHandler::ExtractStringValue( |
54 const base::ListValue* value) { | 64 const base::ListValue* value) { |
55 base::string16 string16_value; | 65 base::string16 string16_value; |
56 if (value->GetString(0, &string16_value)) | 66 if (value->GetString(0, &string16_value)) |
57 return string16_value; | 67 return string16_value; |
58 NOTREACHED(); | 68 NOTREACHED(); |
59 return base::string16(); | 69 return base::string16(); |
60 } | 70 } |
61 | 71 |
62 void WebUIMessageHandler::RenderViewReused() { | 72 void WebUIMessageHandler::RenderViewReused() { |
63 if (!javascript_allowed_) | 73 DisallowJavascript(); |
64 return; | |
65 | |
66 javascript_allowed_ = false; | |
67 OnJavascriptDisallowed(); | |
68 } | 74 } |
69 | 75 |
70 } // namespace content | 76 } // namespace content |
OLD | NEW |