Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: content/browser/webui/web_ui_message_handler.cc

Issue 1896463003: WebUI: Add JavaScript lifecycle-control to WebUIMessageHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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() {
15 if (javascript_allowed_)
16 return;
17
18 javascript_allowed_ = true;
19 CHECK(IsJavascriptAllowed());
20
21 OnJavascriptAllowed();
22 }
23
24 bool WebUIMessageHandler::IsJavascriptAllowed() const {
25 return javascript_allowed_ && web_ui() && web_ui()->CanCallJavascript();
26 }
27
14 bool WebUIMessageHandler::ExtractIntegerValue(const base::ListValue* value, 28 bool WebUIMessageHandler::ExtractIntegerValue(const base::ListValue* value,
15 int* out_int) { 29 int* out_int) {
16 std::string string_value; 30 std::string string_value;
17 if (value->GetString(0, &string_value)) 31 if (value->GetString(0, &string_value))
18 return base::StringToInt(string_value, out_int); 32 return base::StringToInt(string_value, out_int);
19 double double_value; 33 double double_value;
20 if (value->GetDouble(0, &double_value)) { 34 if (value->GetDouble(0, &double_value)) {
21 *out_int = static_cast<int>(double_value); 35 *out_int = static_cast<int>(double_value);
22 return true; 36 return true;
23 } 37 }
(...skipping 14 matching lines...) Expand all
38 52
39 base::string16 WebUIMessageHandler::ExtractStringValue( 53 base::string16 WebUIMessageHandler::ExtractStringValue(
40 const base::ListValue* value) { 54 const base::ListValue* value) {
41 base::string16 string16_value; 55 base::string16 string16_value;
42 if (value->GetString(0, &string16_value)) 56 if (value->GetString(0, &string16_value))
43 return string16_value; 57 return string16_value;
44 NOTREACHED(); 58 NOTREACHED();
45 return base::string16(); 59 return base::string16();
46 } 60 }
47 61
62 void WebUIMessageHandler::RenderViewReused() {
63 if (!javascript_allowed_)
64 return;
65
66 javascript_allowed_ = false;
67 OnJavascriptDisallowed();
68 }
69
48 } // namespace content 70 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698