Commit 9dd5cbb7 authored by tedchoc@chromium.org's avatar tedchoc@chromium.org

Add the webui handler for Android's bookmark section on the NTP.

BUG=137011


Review URL: https://chromiumcodereview.appspot.com/10829326

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152226 0039d316-1c4b-4281-b951-d872f2087c98
parent 8d13c6f7
...@@ -472,7 +472,7 @@ cr.define('ntp', function() { ...@@ -472,7 +472,7 @@ cr.define('ntp', function() {
browseToBookmarkFolder(item.id); browseToBookmarkFolder(item.id);
} else { } else {
if (bookmarkShortcutMode) { if (bookmarkShortcutMode) {
chrome.send('shortcutToBookmark', [item.id]); chrome.send('createHomeScreenBookmarkShortcut', [item.id]);
} else if (!!item.url) { } else if (!!item.url) {
window.location = item.url; window.location = item.url;
} }
...@@ -1107,7 +1107,7 @@ cr.define('ntp', function() { ...@@ -1107,7 +1107,7 @@ cr.define('ntp', function() {
case ContextMenuItemIds.BOOKMARK_SHORTCUT: case ContextMenuItemIds.BOOKMARK_SHORTCUT:
if (contextMenuUrl != null) if (contextMenuUrl != null)
chrome.send('shortcutToBookmark', [contextMenuItem.id]); chrome.send('createHomeScreenBookmarkShortcut', [contextMenuItem.id]);
break; break;
case ContextMenuItemIds.RECENTLY_CLOSED_REMOVE: case ContextMenuItemIds.RECENTLY_CLOSED_REMOVE:
......
This diff is collapsed.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_NTP_ANDROID_BOOKMARKS_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_NTP_ANDROID_BOOKMARKS_HANDLER_H_
#include "base/values.h"
#include "chrome/browser/bookmarks/base_bookmark_model_observer.h"
#include "chrome/browser/cancelable_request.h"
#include "chrome/browser/favicon/favicon_service.h"
#include "chrome/browser/ui/webui/ntp/android/partner_bookmarks_shim.h"
#include "content/public/browser/web_ui_message_handler.h"
// The handler for Javascript messages related to the bookmarks.
//
// In Javascript if getBookmarks() is called without any parameter, the 'Other
// Bookmark' folder and bookmark bar's bookmarks and folders are returned.
// If getBookmarks() is called with a valid bookmark folder id, the given
// folder's bookmarks and sub folders of are returned.
//
// All bookmarks and subfolder is returned by bookmarks() javascript callback
// function.
// The returned field 'folder' indicates whether the data is a folder. The
// returned field 'root' indicates whether or not the bookmark list that was
// returned is the root list or not. Besides these fields, a folder has id
// and title fields; A bookmark has url and title fields.
//
// A sample result looks like:
// {
// title: 'Bookmark Bar',
// id: '1',
// root: true,
// bookmarks: [
// {
// title: 'Cake',
// url: 'http://www.google.com',
// folder: false
// },
// {
// title: 'Puppies',
// folder: true,
// id: '2'
// }
// ]
// }
class BookmarksHandler : public content::WebUIMessageHandler,
public BaseBookmarkModelObserver,
public PartnerBookmarksShim::Observer {
public:
BookmarksHandler();
virtual ~BookmarksHandler();
// WebUIMessageHandler override and implementation.
virtual void RegisterMessages() OVERRIDE;
// Callback for the "getBookmarks" message.
void HandleGetBookmarks(const ListValue* args);
// Callback for the "deleteBookmark" message.
void HandleDeleteBookmark(const ListValue* args);
// Callback for the "createHomeScreenBookmarkShortcut" message. Used when
// creating a shortcut on the home screen that should open the bookmark
// specified in |args|.
void HandleCreateHomeScreenBookmarkShortcut(const base::ListValue* args);
// Notify the UI that a change occurred to the bookmark model.
virtual void NotifyModelChanged(const DictionaryValue& status);
// Override the methods of BookmarkModelObserver
virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE;
virtual void BookmarkModelChanged() OVERRIDE;
virtual void ExtensiveBookmarkChangesBeginning(BookmarkModel* model) OVERRIDE;
virtual void ExtensiveBookmarkChangesEnded(BookmarkModel* model) OVERRIDE;
virtual void BookmarkNodeRemoved(BookmarkModel* model,
const BookmarkNode* parent,
int old_index,
const BookmarkNode* node) OVERRIDE;
virtual void BookmarkNodeAdded(BookmarkModel* model,
const BookmarkNode* parent,
int index) OVERRIDE;
virtual void BookmarkNodeChanged(BookmarkModel* model,
const BookmarkNode* node) OVERRIDE;
// Override the methods of PartnerBookmarksShim::Observer
virtual void PartnerShimLoaded(PartnerBookmarksShim* shim) OVERRIDE;
virtual void ShimBeingDeleted(PartnerBookmarksShim* shim) OVERRIDE;
private:
// The bookmark model being observed (if it has been attached).
BookmarkModel* bookmark_model_;
// Information about the Partner bookmarks (must check for IsLoaded())
PartnerBookmarksShim* partner_bookmarks_shim_;
// Whether the bookmark data has been requested by the UI yet.
bool bookmark_data_requested_;
// Indicates that extensive changes to the BookmarkModel is on-going.
bool extensive_changes_;
// Used for loading bookmark node.
CancelableRequestConsumerTSimple<const BookmarkNode*> cancelable_consumer_;
// Generates the string encoded ID to be used by the NTP.
std::string GetBookmarkIdForNtp(const BookmarkNode* node);
// Sets the necessary parent information in the response object to be sent
// to the UI renderer.
void SetParentInBookmarksResult(const BookmarkNode* parent,
DictionaryValue* result);
// Convert the given bookmark |node| into a dictionary format to be returned
// to JavaScript.
void PopulateBookmark(const BookmarkNode* node, ListValue* result);
// Given a bookmark folder node, |folder|, populate the |result| with the
// structured JavaScript-formatted data regarding the folder.
void PopulateBookmarksInFolder(const BookmarkNode* folder,
DictionaryValue* result);
// Sends all bookmarks and sub folders in the given folder back to the NTP.
void QueryBookmarkFolder(const int64& id, bool is_partner_bookmark);
// Sends bookmark bar's bookmarks and sub folders and other folders back to
// NTP.
void QueryInitialBookmarks();
// Sends the result back to Javascript
void SendResult(const DictionaryValue& result);
// Called once the favicon is loaded during creation of the bookmark shortcuts
// and is available for use.
void OnShortcutFaviconDataAvailable(FaviconService::Handle handle,
history::FaviconData favicon);
DISALLOW_COPY_AND_ASSIGN(BookmarksHandler);
};
#endif // CHROME_BROWSER_UI_WEBUI_NTP_ANDROID_BOOKMARKS_HANDLER_H_
...@@ -59,6 +59,8 @@ ...@@ -59,6 +59,8 @@
#include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h" #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h"
#include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h"
#include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h" #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h"
#else
#include "chrome/browser/ui/webui/ntp/android/bookmarks_handler.h"
#endif #endif
using content::BrowserThread; using content::BrowserThread;
...@@ -127,7 +129,10 @@ NewTabUI::NewTabUI(content::WebUI* web_ui) ...@@ -127,7 +129,10 @@ NewTabUI::NewTabUI(content::WebUI* web_ui)
web_ui->AddMessageHandler(new FaviconWebUIHandler()); web_ui->AddMessageHandler(new FaviconWebUIHandler());
} }
#if !defined(OS_ANDROID) #if defined(OS_ANDROID)
// These handlers are specific to the Android NTP page.
web_ui->AddMessageHandler((new BookmarksHandler()));
#else
// Android uses native UI for sync setup. // Android uses native UI for sync setup.
if (NTPLoginHandler::ShouldShow(GetProfile())) if (NTPLoginHandler::ShouldShow(GetProfile()))
web_ui->AddMessageHandler(new NTPLoginHandler()); web_ui->AddMessageHandler(new NTPLoginHandler());
......
...@@ -4973,6 +4973,8 @@ ...@@ -4973,6 +4973,8 @@
'chrome_browser_jni_headers', 'chrome_browser_jni_headers',
], ],
'sources': [ 'sources': [
'browser/ui/webui/ntp/android/bookmarks_handler.cc',
'browser/ui/webui/ntp/android/bookmarks_handler.h',
'browser/ui/webui/ntp/android/partner_bookmarks_shim.cc', 'browser/ui/webui/ntp/android/partner_bookmarks_shim.cc',
'browser/ui/webui/ntp/android/partner_bookmarks_shim.h', 'browser/ui/webui/ntp/android/partner_bookmarks_shim.h',
], ],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment