| 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 "content/browser/webui/generic_handler.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/bind_helpers.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "base/values.h" | |
| 11 #include "content/browser/disposition_utils.h" | |
| 12 #include "content/browser/webui/web_ui_impl.h" | |
| 13 #include "content/public/browser/web_contents.h" | |
| 14 | |
| 15 using content::OpenURLParams; | |
| 16 | |
| 17 GenericHandler::GenericHandler() { | |
| 18 } | |
| 19 | |
| 20 GenericHandler::~GenericHandler() { | |
| 21 } | |
| 22 | |
| 23 void GenericHandler::RegisterMessages() { | |
| 24 web_ui()->RegisterMessageCallback("navigateToUrl", | |
| 25 base::Bind(&GenericHandler::HandleNavigateToUrl, base::Unretained(this))); | |
| 26 } | |
| 27 | |
| 28 void GenericHandler::HandleNavigateToUrl(const ListValue* args) { | |
| 29 std::string url_string; | |
| 30 std::string target_string; | |
| 31 double button; | |
| 32 bool alt_key; | |
| 33 bool ctrl_key; | |
| 34 bool meta_key; | |
| 35 bool shift_key; | |
| 36 | |
| 37 CHECK(args->GetString(0, &url_string)); | |
| 38 CHECK(args->GetString(1, &target_string)); | |
| 39 CHECK(args->GetDouble(2, &button)); | |
| 40 CHECK(args->GetBoolean(3, &alt_key)); | |
| 41 CHECK(args->GetBoolean(4, &ctrl_key)); | |
| 42 CHECK(args->GetBoolean(5, &meta_key)); | |
| 43 CHECK(args->GetBoolean(6, &shift_key)); | |
| 44 | |
| 45 CHECK(button == 0.0 || button == 1.0); | |
| 46 bool middle_button = (button == 1.0); | |
| 47 | |
| 48 WindowOpenDisposition disposition = | |
| 49 disposition_utils::DispositionFromClick(middle_button, alt_key, ctrl_key, | |
| 50 meta_key, shift_key); | |
| 51 if (disposition == CURRENT_TAB && target_string == "_blank") | |
| 52 disposition = NEW_FOREGROUND_TAB; | |
| 53 | |
| 54 web_ui()->GetWebContents()->OpenURL(OpenURLParams( | |
| 55 GURL(url_string), content::Referrer(), disposition, | |
| 56 content::PAGE_TRANSITION_LINK, false)); | |
| 57 | |
| 58 // This may delete us! | |
| 59 } | |
| OLD | NEW |