OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/dom_ui/generic_handler.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/values.h" |
| 9 #include "chrome/browser/tab_contents/tab_contents.h" |
| 10 #include "googleurl/src/gurl.h" |
| 11 |
| 12 GenericHandler::GenericHandler() { |
| 13 } |
| 14 |
| 15 GenericHandler::~GenericHandler() { |
| 16 } |
| 17 |
| 18 void GenericHandler::RegisterMessages() { |
| 19 dom_ui_->RegisterMessageCallback("navigateToUrl", |
| 20 NewCallback(this, &GenericHandler::HandleNavigateToUrl)); |
| 21 } |
| 22 |
| 23 void GenericHandler::HandleNavigateToUrl(const ListValue* args) { |
| 24 std::string url_string; |
| 25 CHECK(args->GetString(0, &url_string)); |
| 26 std::string button_string; |
| 27 CHECK(args->GetString(1, &button_string)); |
| 28 CHECK(button_string == "0" || button_string == "1"); |
| 29 std::string ctrl_string; |
| 30 CHECK(args->GetString(2, &ctrl_string)); |
| 31 std::string shift_string; |
| 32 CHECK(args->GetString(3, &shift_string)); |
| 33 std::string alt_string; |
| 34 CHECK(args->GetString(4, &alt_string)); |
| 35 |
| 36 // TODO(estade): This logic is replicated in 4 places throughout chrome. |
| 37 // It would be nice to centralize it. |
| 38 WindowOpenDisposition disposition; |
| 39 if (button_string == "1" || ctrl_string == "true") { |
| 40 disposition = shift_string == "true" ? |
| 41 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; |
| 42 } else if (shift_string == "true") { |
| 43 disposition = NEW_WINDOW; |
| 44 } else { |
| 45 disposition = alt_string == "true" ? SAVE_TO_DISK : CURRENT_TAB; |
| 46 } |
| 47 |
| 48 dom_ui_->tab_contents()->OpenURL( |
| 49 GURL(url_string), GURL(), disposition, PageTransition::LINK); |
| 50 |
| 51 // This may delete us! |
| 52 } |
OLD | NEW |