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

Side by Side Diff: chrome/browser/ui/webui/instant_ui.cc

Issue 12377095: Add "clear" to about://instant. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 7 years, 9 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
« no previous file with comments | « chrome/browser/resources/instant/instant.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/ui/webui/instant_ui.h" 5 #include "chrome/browser/ui/webui/instant_ui.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 InstantUIMessageHandler(); 51 InstantUIMessageHandler();
52 virtual ~InstantUIMessageHandler(); 52 virtual ~InstantUIMessageHandler();
53 53
54 // WebUIMessageHandler implementation. 54 // WebUIMessageHandler implementation.
55 virtual void RegisterMessages() OVERRIDE; 55 virtual void RegisterMessages() OVERRIDE;
56 56
57 private: 57 private:
58 void GetPreferenceValue(const base::ListValue* args); 58 void GetPreferenceValue(const base::ListValue* args);
59 void SetPreferenceValue(const base::ListValue* args); 59 void SetPreferenceValue(const base::ListValue* args);
60 void GetDebugInfo(const base::ListValue* value); 60 void GetDebugInfo(const base::ListValue* value);
61 void ClearDebugInfo(const base::ListValue* value);
61 62
62 DISALLOW_COPY_AND_ASSIGN(InstantUIMessageHandler); 63 DISALLOW_COPY_AND_ASSIGN(InstantUIMessageHandler);
63 }; 64 };
64 65
65 InstantUIMessageHandler::InstantUIMessageHandler() {} 66 InstantUIMessageHandler::InstantUIMessageHandler() {}
66 67
67 InstantUIMessageHandler::~InstantUIMessageHandler() {} 68 InstantUIMessageHandler::~InstantUIMessageHandler() {}
68 69
69 void InstantUIMessageHandler::RegisterMessages() { 70 void InstantUIMessageHandler::RegisterMessages() {
70 web_ui()->RegisterMessageCallback( 71 web_ui()->RegisterMessageCallback(
71 "getPreferenceValue", 72 "getPreferenceValue",
72 base::Bind(&InstantUIMessageHandler::GetPreferenceValue, 73 base::Bind(&InstantUIMessageHandler::GetPreferenceValue,
73 base::Unretained(this))); 74 base::Unretained(this)));
74 web_ui()->RegisterMessageCallback( 75 web_ui()->RegisterMessageCallback(
75 "setPreferenceValue", 76 "setPreferenceValue",
76 base::Bind(&InstantUIMessageHandler::SetPreferenceValue, 77 base::Bind(&InstantUIMessageHandler::SetPreferenceValue,
77 base::Unretained(this))); 78 base::Unretained(this)));
78 web_ui()->RegisterMessageCallback( 79 web_ui()->RegisterMessageCallback(
79 "getDebugInfo", 80 "getDebugInfo",
80 base::Bind(&InstantUIMessageHandler::GetDebugInfo, 81 base::Bind(&InstantUIMessageHandler::GetDebugInfo,
81 base::Unretained(this))); 82 base::Unretained(this)));
83 web_ui()->RegisterMessageCallback(
84 "clearDebugInfo",
85 base::Bind(&InstantUIMessageHandler::ClearDebugInfo,
86 base::Unretained(this)));
82 } 87 }
83 88
84 void InstantUIMessageHandler::GetPreferenceValue(const base::ListValue* args) { 89 void InstantUIMessageHandler::GetPreferenceValue(const base::ListValue* args) {
85 std::string pref_name; 90 std::string pref_name;
86 if (!args->GetString(0, &pref_name)) return; 91 if (!args->GetString(0, &pref_name)) return;
87 92
88 base::StringValue pref_name_value(pref_name); 93 base::StringValue pref_name_value(pref_name);
89 if (pref_name == prefs::kInstantUIZeroSuggestUrlPrefix) { 94 if (pref_name == prefs::kInstantUIZeroSuggestUrlPrefix) {
90 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); 95 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
91 base::StringValue arg(prefs->GetString(pref_name.c_str())); 96 base::StringValue arg(prefs->GetString(pref_name.c_str()));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 entry->SetString("time", FormatTime(it->first)); 134 entry->SetString("time", FormatTime(it->first));
130 entry->SetString("text", it->second); 135 entry->SetString("text", it->second);
131 entries->Append(entry); 136 entries->Append(entry);
132 } 137 }
133 data.Set("entries", entries); 138 data.Set("entries", entries);
134 139
135 web_ui()->CallJavascriptFunction("instantConfig.getDebugInfoResult", data); 140 web_ui()->CallJavascriptFunction("instantConfig.getDebugInfoResult", data);
136 #endif 141 #endif
137 } 142 }
138 143
144 void InstantUIMessageHandler::ClearDebugInfo(const base::ListValue* args) {
145 #if !defined(OS_ANDROID)
146 if (!web_ui()->GetWebContents())
147 return;
148 Browser* browser = chrome::FindBrowserWithWebContents(
149 web_ui()->GetWebContents());
150 if (!browser || !browser->instant_controller())
151 return;
152
153 browser->instant_controller()->instant()->ClearDebugEvents();
154 #endif
155 }
156
139 } // namespace 157 } // namespace
140 158
141 //////////////////////////////////////////////////////////////////////////////// 159 ////////////////////////////////////////////////////////////////////////////////
142 // InstantUI 160 // InstantUI
143 161
144 InstantUI::InstantUI(content::WebUI* web_ui) : WebUIController(web_ui) { 162 InstantUI::InstantUI(content::WebUI* web_ui) : WebUIController(web_ui) {
145 web_ui->AddMessageHandler(new InstantUIMessageHandler()); 163 web_ui->AddMessageHandler(new InstantUIMessageHandler());
146 164
147 // Set up the chrome://instant/ source. 165 // Set up the chrome://instant/ source.
148 Profile* profile = Profile::FromWebUI(web_ui); 166 Profile* profile = Profile::FromWebUI(web_ui);
149 content::WebUIDataSource::Add(profile, CreateInstantHTMLSource()); 167 content::WebUIDataSource::Add(profile, CreateInstantHTMLSource());
150 } 168 }
151 169
152 // static 170 // static
153 void InstantUI::RegisterUserPrefs(PrefRegistrySyncable* registry) { 171 void InstantUI::RegisterUserPrefs(PrefRegistrySyncable* registry) {
154 registry->RegisterStringPref(prefs::kInstantUIZeroSuggestUrlPrefix, "", 172 registry->RegisterStringPref(prefs::kInstantUIZeroSuggestUrlPrefix, "",
155 PrefRegistrySyncable::UNSYNCABLE_PREF); 173 PrefRegistrySyncable::UNSYNCABLE_PREF);
156 } 174 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/instant/instant.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698