Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates the UserNotesTabHelper class that monitors Primary Page changes and navigations for the WebContents it's attached to. When the Primary Page changes, a UserNotesManager is attached to it (via PageUserData). When a navigation occurs (excluding errors, non-committed, same-document or outside the primary main frame), the UserNoteService is notified so it can deal with notes for the new page. The UserNotesTabHelper is only attached if the User Notes feature is enabled, if the session isn't off the record, and if the platform is non-mobile. Also adds the service method that the tab helper must use to notify the service of navigations (left unimplemented for now). Bug: 1303900 Change-Id: Id700fe0c920c4076a3ce76949371508857a25826 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3558830 Reviewed-by: David Bokan <bokan@chromium.org> Reviewed-by: Avi Drissman <avi@chromium.org> Commit-Queue: Guillaume Jenkins <gujen@google.com> Cr-Commit-Position: refs/heads/main@{#989076}
- Loading branch information
1 parent
639a247
commit a288ef2
Showing
8 changed files
with
134 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2022 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. | ||
|
||
#include "chrome/browser/user_notes/user_notes_tab_helper.h" | ||
|
||
#include "chrome/browser/user_notes/user_note_service_factory.h" | ||
#include "components/user_notes/browser/user_note_service.h" | ||
#include "components/user_notes/browser/user_notes_manager.h" | ||
#include "content/public/browser/navigation_handle.h" | ||
#include "content/public/browser/page.h" | ||
#include "content/public/browser/render_frame_host.h" | ||
#include "content/public/browser/web_contents.h" | ||
|
||
namespace user_notes { | ||
|
||
UserNotesTabHelper::UserNotesTabHelper(content::WebContents* web_contents) | ||
: WebContentsObserver(web_contents), | ||
content::WebContentsUserData<UserNotesTabHelper>(*web_contents) {} | ||
|
||
UserNotesTabHelper::~UserNotesTabHelper() = default; | ||
|
||
void UserNotesTabHelper::PrimaryPageChanged(content::Page& page) { | ||
if (!UserNotesManager::GetForPage(page)) { | ||
UserNotesManager::CreateForPage(page, service()->GetSafeRef()); | ||
} | ||
} | ||
|
||
void UserNotesTabHelper::DidFinishNavigation( | ||
content::NavigationHandle* navigation_handle) { | ||
// Note: `DidFinishNavigation` is needed in addition to `PrimaryPageChanged` | ||
// because of non-main frame navigations. | ||
if (!navigation_handle->HasCommitted() || | ||
navigation_handle->IsSameDocument()) { | ||
return; | ||
} | ||
service()->OnFrameNavigated(navigation_handle->GetRenderFrameHost()); | ||
} | ||
|
||
UserNoteService* UserNotesTabHelper::service() const { | ||
return UserNoteServiceFactory::GetForContext( | ||
web_contents()->GetBrowserContext()); | ||
} | ||
|
||
WEB_CONTENTS_USER_DATA_KEY_IMPL(UserNotesTabHelper); | ||
|
||
} // namespace user_notes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2022 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_USER_NOTES_USER_NOTES_TAB_HELPER_H_ | ||
#define CHROME_BROWSER_USER_NOTES_USER_NOTES_TAB_HELPER_H_ | ||
|
||
#include "content/public/browser/web_contents_observer.h" | ||
#include "content/public/browser/web_contents_user_data.h" | ||
|
||
namespace content { | ||
class NavigationHandle; | ||
class Page; | ||
class WebContents; | ||
} // namespace content | ||
|
||
namespace user_notes { | ||
|
||
class UserNoteService; | ||
|
||
// An observer of WebContents that attaches User Notes page data to primary | ||
// pages, and notifies the User Notes service when new URLs are navigated to so | ||
// it can display notes. | ||
class UserNotesTabHelper | ||
: public content::WebContentsObserver, | ||
public content::WebContentsUserData<UserNotesTabHelper> { | ||
public: | ||
UserNotesTabHelper(const UserNotesTabHelper&) = delete; | ||
UserNotesTabHelper& operator=(const UserNotesTabHelper&) = delete; | ||
|
||
~UserNotesTabHelper() override; | ||
|
||
private: | ||
friend class content::WebContentsUserData<UserNotesTabHelper>; | ||
|
||
explicit UserNotesTabHelper(content::WebContents* web_contents); | ||
|
||
UserNoteService* service() const; | ||
|
||
// WebContentsObserver implementation. | ||
void PrimaryPageChanged(content::Page& page) override; | ||
|
||
void DidFinishNavigation( | ||
content::NavigationHandle* navigation_handle) override; | ||
|
||
WEB_CONTENTS_USER_DATA_KEY_DECL(); | ||
}; | ||
|
||
} // namespace user_notes | ||
|
||
#endif // CHROME_BROWSER_USER_NOTES_USER_NOTES_TAB_HELPER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters