OLD | NEW |
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/bookmarks/bookmark_manager_extension_api.h" | 5 #include "chrome/browser/bookmarks/bookmark_manager_extension_api.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/bookmarks/bookmark_extension_api_constants.h" | 12 #include "chrome/browser/bookmarks/bookmark_extension_api_constants.h" |
13 #include "chrome/browser/bookmarks/bookmark_extension_helpers.h" | 13 #include "chrome/browser/bookmarks/bookmark_extension_helpers.h" |
14 #include "chrome/browser/bookmarks/bookmark_model.h" | 14 #include "chrome/browser/bookmarks/bookmark_model.h" |
15 #include "chrome/browser/bookmarks/bookmark_node_data.h" | 15 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
16 #include "chrome/browser/bookmarks/bookmark_utils.h" | 16 #include "chrome/browser/bookmarks/bookmark_utils.h" |
17 #include "chrome/browser/extensions/extension_event_router.h" | 17 #include "chrome/browser/extensions/extension_event_router.h" |
18 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 18 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
19 #include "chrome/browser/extensions/extension_web_ui.h" | 19 #include "chrome/browser/extensions/extension_web_ui.h" |
20 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
23 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 23 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
24 #include "chrome/common/chrome_view_type.h" | 24 #include "chrome/common/chrome_view_type.h" |
25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
26 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
27 #include "content/public/browser/render_view_host_delegate.h" | |
28 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
29 #include "content/public/browser/web_ui.h" | 28 #include "content/public/browser/web_ui.h" |
30 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
31 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
32 | 31 |
33 namespace keys = bookmark_extension_api_constants; | 32 namespace keys = bookmark_extension_api_constants; |
34 | 33 |
35 using content::WebContents; | 34 using content::WebContents; |
36 | 35 |
37 namespace { | 36 namespace { |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 } | 377 } |
379 | 378 |
380 bool StartDragBookmarkManagerFunction::RunImpl() { | 379 bool StartDragBookmarkManagerFunction::RunImpl() { |
381 if (!EditBookmarksEnabled()) | 380 if (!EditBookmarksEnabled()) |
382 return false; | 381 return false; |
383 BookmarkModel* model = profile()->GetBookmarkModel(); | 382 BookmarkModel* model = profile()->GetBookmarkModel(); |
384 std::vector<const BookmarkNode*> nodes; | 383 std::vector<const BookmarkNode*> nodes; |
385 EXTENSION_FUNCTION_VALIDATE( | 384 EXTENSION_FUNCTION_VALIDATE( |
386 GetNodesFromArguments(model, args_.get(), 0, &nodes)); | 385 GetNodesFromArguments(model, args_.get(), 0, &nodes)); |
387 | 386 |
388 if (render_view_host_->GetDelegate()->GetRenderViewType() == | 387 WebContents* web_contents = |
389 chrome::VIEW_TYPE_TAB_CONTENTS) { | 388 WebContents::FromRenderViewHost(render_view_host_); |
| 389 if (chrome::GetViewType(web_contents) == chrome::VIEW_TYPE_TAB_CONTENTS) { |
390 WebContents* web_contents = | 390 WebContents* web_contents = |
391 dispatcher()->delegate()->GetAssociatedWebContents(); | 391 dispatcher()->delegate()->GetAssociatedWebContents(); |
392 CHECK(web_contents); | 392 CHECK(web_contents); |
393 bookmark_utils::DragBookmarks(profile(), nodes, | 393 bookmark_utils::DragBookmarks(profile(), nodes, |
394 web_contents->GetNativeView()); | 394 web_contents->GetNativeView()); |
395 | 395 |
396 return true; | 396 return true; |
397 } else { | 397 } else { |
398 NOTREACHED(); | 398 NOTREACHED(); |
399 return false; | 399 return false; |
(...skipping 20 matching lines...) Expand all Loading... |
420 error_ = keys::kNoParentError; | 420 error_ = keys::kNoParentError; |
421 return false; | 421 return false; |
422 } | 422 } |
423 | 423 |
424 int drop_index; | 424 int drop_index; |
425 if (HasOptionalArgument(1)) | 425 if (HasOptionalArgument(1)) |
426 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &drop_index)); | 426 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &drop_index)); |
427 else | 427 else |
428 drop_index = drop_parent->child_count(); | 428 drop_index = drop_parent->child_count(); |
429 | 429 |
430 if (render_view_host_->GetDelegate()->GetRenderViewType() == | 430 WebContents* web_contents = |
431 chrome::VIEW_TYPE_TAB_CONTENTS) { | 431 WebContents::FromRenderViewHost(render_view_host_); |
| 432 if (chrome::GetViewType(web_contents) == chrome::VIEW_TYPE_TAB_CONTENTS) { |
432 WebContents* web_contents = | 433 WebContents* web_contents = |
433 dispatcher()->delegate()->GetAssociatedWebContents(); | 434 dispatcher()->delegate()->GetAssociatedWebContents(); |
434 CHECK(web_contents); | 435 CHECK(web_contents); |
435 ExtensionWebUI* web_ui = | 436 ExtensionWebUI* web_ui = |
436 static_cast<ExtensionWebUI*>(web_contents->GetWebUI()->GetController()); | 437 static_cast<ExtensionWebUI*>(web_contents->GetWebUI()->GetController()); |
437 CHECK(web_ui); | 438 CHECK(web_ui); |
438 BookmarkManagerExtensionEventRouter* router = | 439 BookmarkManagerExtensionEventRouter* router = |
439 web_ui->bookmark_manager_extension_event_router(); | 440 web_ui->bookmark_manager_extension_event_router(); |
440 | 441 |
441 DCHECK(router); | 442 DCHECK(router); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 bool CanEditBookmarkManagerFunction::RunImpl() { | 493 bool CanEditBookmarkManagerFunction::RunImpl() { |
493 result_.reset(Value::CreateBooleanValue( | 494 result_.reset(Value::CreateBooleanValue( |
494 profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled))); | 495 profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled))); |
495 return true; | 496 return true; |
496 } | 497 } |
497 | 498 |
498 bool RecordLaunchBookmarkFunction::RunImpl() { | 499 bool RecordLaunchBookmarkFunction::RunImpl() { |
499 bookmark_utils::RecordBookmarkLaunch(bookmark_utils::LAUNCH_MANAGER); | 500 bookmark_utils::RecordBookmarkLaunch(bookmark_utils::LAUNCH_MANAGER); |
500 return true; | 501 return true; |
501 } | 502 } |
OLD | NEW |