OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/storage/durable_storage_permission_context.h" | 5 #include "chrome/browser/storage/durable_storage_permission_context.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 content::WebContents* web_contents, | 33 content::WebContents* web_contents, |
34 const PermissionRequestID& id, | 34 const PermissionRequestID& id, |
35 const GURL& requesting_origin, | 35 const GURL& requesting_origin, |
36 const GURL& embedding_origin, | 36 const GURL& embedding_origin, |
37 bool user_gesture, | 37 bool user_gesture, |
38 const BrowserPermissionCallback& callback) { | 38 const BrowserPermissionCallback& callback) { |
39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
40 | 40 |
41 // TODO(dgrogan): Remove bookmarks check in favor of site engagement. In the | 41 // TODO(dgrogan): Remove bookmarks check in favor of site engagement. In the |
42 // meantime maybe grant permission to A2HS origins as well. | 42 // meantime maybe grant permission to A2HS origins as well. |
43 BookmarkModel* model = BookmarkModelFactory::GetForProfileIfExists(profile()); | 43 BookmarkModel* model = |
| 44 BookmarkModelFactory::GetForBrowserContextIfExists(profile()); |
44 if (model) { | 45 if (model) { |
45 std::vector<bookmarks::BookmarkModel::URLAndTitle> bookmarks; | 46 std::vector<bookmarks::BookmarkModel::URLAndTitle> bookmarks; |
46 model->GetBookmarks(&bookmarks); | 47 model->GetBookmarks(&bookmarks); |
47 if (IsOriginBookmarked(bookmarks, requesting_origin)) { | 48 if (IsOriginBookmarked(bookmarks, requesting_origin)) { |
48 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 49 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
49 true /* persist */, CONTENT_SETTING_ALLOW); | 50 true /* persist */, CONTENT_SETTING_ALLOW); |
50 return; | 51 return; |
51 } | 52 } |
52 } | 53 } |
53 | 54 |
(...skipping 24 matching lines...) Expand all Loading... |
78 const std::vector<bookmarks::BookmarkModel::URLAndTitle>& bookmarks, | 79 const std::vector<bookmarks::BookmarkModel::URLAndTitle>& bookmarks, |
79 const GURL& origin) { | 80 const GURL& origin) { |
80 BookmarkModel::URLAndTitle looking_for; | 81 BookmarkModel::URLAndTitle looking_for; |
81 looking_for.url = origin; | 82 looking_for.url = origin; |
82 return std::binary_search(bookmarks.begin(), bookmarks.end(), looking_for, | 83 return std::binary_search(bookmarks.begin(), bookmarks.end(), looking_for, |
83 [](const BookmarkModel::URLAndTitle& a, | 84 [](const BookmarkModel::URLAndTitle& a, |
84 const BookmarkModel::URLAndTitle& b) { | 85 const BookmarkModel::URLAndTitle& b) { |
85 return a.url.GetOrigin() < b.url.GetOrigin(); | 86 return a.url.GetOrigin() < b.url.GetOrigin(); |
86 }); | 87 }); |
87 } | 88 } |
OLD | NEW |