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

Side by Side Diff: chrome/browser/dom_ui/options/browser_options_handler.cc

Issue 6303003: DOMUI Prefs: Implement inline editability for startup pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Typo fix Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/dom_ui/options/browser_options_handler.h" 5 #include "chrome/browser/dom_ui/options/browser_options_handler.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "base/singleton.h" 10 #include "base/singleton.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 dom_ui_->RegisterMessageCallback( 103 dom_ui_->RegisterMessageCallback(
104 "setDefaultSearchEngine", 104 "setDefaultSearchEngine",
105 NewCallback(this, &BrowserOptionsHandler::SetDefaultSearchEngine)); 105 NewCallback(this, &BrowserOptionsHandler::SetDefaultSearchEngine));
106 dom_ui_->RegisterMessageCallback( 106 dom_ui_->RegisterMessageCallback(
107 "removeStartupPages", 107 "removeStartupPages",
108 NewCallback(this, &BrowserOptionsHandler::RemoveStartupPages)); 108 NewCallback(this, &BrowserOptionsHandler::RemoveStartupPages));
109 dom_ui_->RegisterMessageCallback( 109 dom_ui_->RegisterMessageCallback(
110 "addStartupPage", 110 "addStartupPage",
111 NewCallback(this, &BrowserOptionsHandler::AddStartupPage)); 111 NewCallback(this, &BrowserOptionsHandler::AddStartupPage));
112 dom_ui_->RegisterMessageCallback( 112 dom_ui_->RegisterMessageCallback(
113 "editStartupPage",
114 NewCallback(this, &BrowserOptionsHandler::EditStartupPage));
115 dom_ui_->RegisterMessageCallback(
113 "setStartupPagesToCurrentPages", 116 "setStartupPagesToCurrentPages",
114 NewCallback(this, &BrowserOptionsHandler::SetStartupPagesToCurrentPages)); 117 NewCallback(this, &BrowserOptionsHandler::SetStartupPagesToCurrentPages));
115 } 118 }
116 119
117 void BrowserOptionsHandler::Initialize() { 120 void BrowserOptionsHandler::Initialize() {
118 // Create our favicon data source. 121 // Create our favicon data source.
119 BrowserThread::PostTask( 122 BrowserThread::PostTask(
120 BrowserThread::IO, FROM_HERE, 123 BrowserThread::IO, FROM_HERE,
121 NewRunnableMethod( 124 NewRunnableMethod(
122 ChromeURLDataManager::GetInstance(), 125 ChromeURLDataManager::GetInstance(),
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 void BrowserOptionsHandler::OnModelChanged() { 281 void BrowserOptionsHandler::OnModelChanged() {
279 ListValue startup_pages; 282 ListValue startup_pages;
280 int page_count = startup_custom_pages_table_model_->RowCount(); 283 int page_count = startup_custom_pages_table_model_->RowCount();
281 std::vector<GURL> urls = startup_custom_pages_table_model_->GetURLs(); 284 std::vector<GURL> urls = startup_custom_pages_table_model_->GetURLs();
282 for (int i = 0; i < page_count; ++i) { 285 for (int i = 0; i < page_count; ++i) {
283 DictionaryValue* entry = new DictionaryValue(); 286 DictionaryValue* entry = new DictionaryValue();
284 entry->SetString("title", startup_custom_pages_table_model_->GetText(i, 0)); 287 entry->SetString("title", startup_custom_pages_table_model_->GetText(i, 0));
285 entry->SetString("url", urls[i].spec()); 288 entry->SetString("url", urls[i].spec());
286 entry->SetString("tooltip", 289 entry->SetString("tooltip",
287 startup_custom_pages_table_model_->GetTooltip(i)); 290 startup_custom_pages_table_model_->GetTooltip(i));
291 entry->SetString("modelIndex", base::IntToString(i));
288 startup_pages.Append(entry); 292 startup_pages.Append(entry);
289 } 293 }
290 294
291 dom_ui_->CallJavascriptFunction(L"BrowserOptions.updateStartupPages", 295 dom_ui_->CallJavascriptFunction(L"BrowserOptions.updateStartupPages",
292 startup_pages); 296 startup_pages);
293 } 297 }
294 298
295 void BrowserOptionsHandler::OnItemsChanged(int start, int length) { 299 void BrowserOptionsHandler::OnItemsChanged(int start, int length) {
296 OnModelChanged(); 300 OnModelChanged();
297 } 301 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 index = startup_custom_pages_table_model_->RowCount(); 350 index = startup_custom_pages_table_model_->RowCount();
347 else 351 else
348 ++index; 352 ++index;
349 353
350 GURL url = URLFixerUpper::FixupURL(url_string, std::string()); 354 GURL url = URLFixerUpper::FixupURL(url_string, std::string());
351 355
352 startup_custom_pages_table_model_->Add(index, url); 356 startup_custom_pages_table_model_->Add(index, url);
353 SaveStartupPagesPref(); 357 SaveStartupPagesPref();
354 } 358 }
355 359
360 void BrowserOptionsHandler::EditStartupPage(const ListValue* args) {
361 std::string url_string;
362 std::string index_string;
363 int index;
364 if (args->GetSize() != 2 ||
365 !args->GetString(0, &index_string) ||
366 !base::StringToInt(index_string, &index) ||
367 !args->GetString(1, &url_string)) {
368 NOTREACHED();
Evan Stade 2011/01/13 23:12:46 imo these should be CHECKs. Who actually builds an
stuartmorgan 2011/01/13 23:35:37 Done for all the argument parsing. For the bounds
369 return;
370 };
371
372 if (index < 0 || index > startup_custom_pages_table_model_->RowCount()) {
373 NOTREACHED();
374 return;
375 }
376
377 std::vector<GURL> urls = startup_custom_pages_table_model_->GetURLs();
378 urls[index] = URLFixerUpper::FixupURL(url_string, std::string());
379 startup_custom_pages_table_model_->SetURLs(urls);
380 }
381
356 void BrowserOptionsHandler::SaveStartupPagesPref() { 382 void BrowserOptionsHandler::SaveStartupPagesPref() {
357 PrefService* prefs = dom_ui_->GetProfile()->GetPrefs(); 383 PrefService* prefs = dom_ui_->GetProfile()->GetPrefs();
358 384
359 SessionStartupPref pref = SessionStartupPref::GetStartupPref(prefs); 385 SessionStartupPref pref = SessionStartupPref::GetStartupPref(prefs);
360 pref.urls = startup_custom_pages_table_model_->GetURLs(); 386 pref.urls = startup_custom_pages_table_model_->GetURLs();
361 387
362 SessionStartupPref::SetStartupPref(prefs, pref); 388 SessionStartupPref::SetStartupPref(prefs, pref);
363 } 389 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698