OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/bookmarks_ui.h" | 5 #include "chrome/browser/ui/webui/bookmarks_ui.h" |
6 | 6 |
7 #include "base/memory/ref_counted_memory.h" | 7 #include "base/memory/ref_counted_memory.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_number_conversions.h" | |
11 #include "base/stringprintf.h" | |
12 #include "chrome/browser/bookmarks/bookmark_editor.h" | |
13 #include "chrome/browser/bookmarks/bookmark_model.h" | |
14 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | |
16 #include "chrome/browser/ui/browser_list.h" | |
17 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 11 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
18 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
19 #include "content/browser/browser_thread.h" | 13 #include "content/browser/browser_thread.h" |
20 #include "content/browser/tab_contents/tab_contents.h" | 14 #include "content/browser/tab_contents/tab_contents.h" |
21 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
22 #include "grit/theme_resources_standard.h" | 16 #include "grit/theme_resources_standard.h" |
23 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
24 #include "googleurl/src/gurl.h" | |
25 | |
26 | 18 |
27 //////////////////////////////////////////////////////////////////////////////// | 19 //////////////////////////////////////////////////////////////////////////////// |
28 // | 20 // |
29 // BookmarksUIHTMLSource | 21 // BookmarksUIHTMLSource |
30 // | 22 // |
31 //////////////////////////////////////////////////////////////////////////////// | 23 //////////////////////////////////////////////////////////////////////////////// |
32 | 24 |
33 BookmarksUIHTMLSource::BookmarksUIHTMLSource() | 25 BookmarksUIHTMLSource::BookmarksUIHTMLSource() |
34 : DataSource(chrome::kChromeUIBookmarksHost, MessageLoop::current()) { | 26 : DataSource(chrome::kChromeUIBookmarksHost, MessageLoop::current()) { |
35 } | 27 } |
(...skipping 25 matching lines...) Expand all Loading... |
61 // Set up the chrome://bookmarks/ source. | 53 // Set up the chrome://bookmarks/ source. |
62 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | 54 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
63 profile->GetChromeURLDataManager()->AddDataSource(html_source); | 55 profile->GetChromeURLDataManager()->AddDataSource(html_source); |
64 } | 56 } |
65 | 57 |
66 // static | 58 // static |
67 RefCountedMemory* BookmarksUI::GetFaviconResourceBytes() { | 59 RefCountedMemory* BookmarksUI::GetFaviconResourceBytes() { |
68 return ResourceBundle::GetSharedInstance(). | 60 return ResourceBundle::GetSharedInstance(). |
69 LoadDataResourceBytes(IDR_BOOKMARKS_FAVICON); | 61 LoadDataResourceBytes(IDR_BOOKMARKS_FAVICON); |
70 } | 62 } |
71 | |
72 //////////////////////////////////////////////////////////////////////////////// | |
73 // | |
74 // BookmarkEditor | |
75 // | |
76 //////////////////////////////////////////////////////////////////////////////// | |
77 | |
78 // static | |
79 void BookmarkEditor::ShowWebUI(Profile* profile, | |
80 const EditDetails& details) { | |
81 GURL url(chrome::kChromeUIBookmarksURL); | |
82 if (details.type == EditDetails::EXISTING_NODE) { | |
83 DCHECK(details.existing_node); | |
84 url = url.Resolve(StringPrintf("/#e=%s", | |
85 base::Int64ToString(details.existing_node->id()).c_str())); | |
86 } else if (details.type == EditDetails::NEW_URL) { | |
87 DCHECK(details.parent_node); | |
88 url = url.Resolve(StringPrintf("/#a=%s", | |
89 base::Int64ToString(details.parent_node->id()).c_str())); | |
90 } else { | |
91 NOTREACHED() << "Unhandled bookmark edit details type"; | |
92 } | |
93 // Get parent browser object. | |
94 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); | |
95 DCHECK(browser); | |
96 browser::NavigateParams params( | |
97 browser->GetSingletonTabNavigateParams(url)); | |
98 params.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; | |
99 browser->ShowSingletonTabOverwritingNTP(params); | |
100 } | |
OLD | NEW |