Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 package org.chromium.chrome.browser.preferences; | 5 package org.chromium.chrome.browser.preferences; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.Intent; | 8 import android.content.Intent; |
| 9 import android.content.SharedPreferences; | 9 import android.content.SharedPreferences; |
| 10 import android.content.res.Resources; | 10 import android.content.res.Resources; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 } | 96 } |
| 97 | 97 |
| 98 /** | 98 /** |
| 99 * Initialize the search engine list. | 99 * Initialize the search engine list. |
| 100 */ | 100 */ |
| 101 private void initEntries() { | 101 private void initEntries() { |
| 102 TemplateUrlService templateUrlService = TemplateUrlService.getInstance() ; | 102 TemplateUrlService templateUrlService = TemplateUrlService.getInstance() ; |
| 103 if (!templateUrlService.isLoaded()) { | 103 if (!templateUrlService.isLoaded()) { |
| 104 templateUrlService.registerLoadListener(this); | 104 templateUrlService.registerLoadListener(this); |
| 105 templateUrlService.load(); | 105 templateUrlService.load(); |
| 106 return; // Flow continues in onTemplateUrlServiceLoaded below. | 106 return; |
| 107 } | 107 } |
|
Theresa
2016/10/03 23:50:09
nit: add this comment back?
| |
| 108 | 108 |
| 109 // Fetch all the search engine info and the currently active one. | 109 // Fetch all the search engine info and the currently active one. |
| 110 mSearchEngines = templateUrlService.getLocalizedSearchEngines(); | 110 mSearchEngines = templateUrlService.getLocalizedSearchEngines(); |
| 111 int searchEngineIndex = templateUrlService.getDefaultSearchEngineIndex() ; | 111 int searchEngineIndex = templateUrlService.getDefaultSearchEngineIndex() ; |
| 112 // Convert the TemplateUrl index into an index into mSearchEngines. | 112 // Convert the TemplateUrl index into an index into mSearchEngines. |
| 113 mSelectedSearchEnginePosition = -1; | 113 mSelectedSearchEnginePosition = -1; |
| 114 for (int i = 0; i < mSearchEngines.size(); ++i) { | 114 for (int i = 0; i < mSearchEngines.size(); ++i) { |
| 115 if (mSearchEngines.get(i).getIndex() == searchEngineIndex) { | 115 if (mSearchEngines.get(i).getIndex() == searchEngineIndex) { |
| 116 mSelectedSearchEnginePosition = i; | 116 mSelectedSearchEnginePosition = i; |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Report back what is selected. | 120 // Report back what is selected. |
| 121 mCallback.currentSearchEngineDetermined(toIndex(mSelectedSearchEnginePos ition)); | 121 mCallback.currentSearchEngineDetermined(toIndex(mSelectedSearchEnginePos ition)); |
| 122 } | 122 } |
| 123 | 123 |
| 124 private int toIndex(int position) { | 124 private int toIndex(int position) { |
| 125 return mSearchEngines.get(position).getIndex(); | 125 return mSearchEngines.get(position).getIndex(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 // BaseAdapter: | 128 // BaseAdapter: |
| 129 | 129 |
| 130 @Override | 130 @Override |
| 131 public int getCount() { | 131 public int getCount() { |
| 132 return mSearchEngines.size(); | 132 return mSearchEngines == null ? 0 : mSearchEngines.size(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 @Override | 135 @Override |
| 136 public Object getItem(int pos) { | 136 public Object getItem(int pos) { |
| 137 TemplateUrl templateUrl = mSearchEngines.get(pos); | 137 TemplateUrl templateUrl = mSearchEngines.get(pos); |
| 138 return templateUrl.getShortName(); | 138 return templateUrl.getShortName(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 @Override | 141 @Override |
| 142 public long getItemId(int position) { | 142 public long getItemId(int position) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 | 215 |
| 216 return view; | 216 return view; |
| 217 } | 217 } |
| 218 | 218 |
| 219 // TemplateUrlService.LoadListener | 219 // TemplateUrlService.LoadListener |
| 220 | 220 |
| 221 @Override | 221 @Override |
| 222 public void onTemplateUrlServiceLoaded() { | 222 public void onTemplateUrlServiceLoaded() { |
| 223 TemplateUrlService.getInstance().unregisterLoadListener(this); | 223 TemplateUrlService.getInstance().unregisterLoadListener(this); |
| 224 initEntries(); | 224 initEntries(); |
| 225 notifyDataSetChanged(); | |
| 225 } | 226 } |
| 226 | 227 |
| 227 // OnClickListener: | 228 // OnClickListener: |
| 228 | 229 |
| 229 @Override | 230 @Override |
| 230 public void onClick(View view) { | 231 public void onClick(View view) { |
| 231 if (view.getTag() == null) { | 232 if (view.getTag() == null) { |
| 232 onLocationLinkClicked(); | 233 onLocationLinkClicked(); |
| 233 } else { | 234 } else { |
| 234 searchEngineSelected((int) view.getTag()); | 235 searchEngineSelected((int) view.getTag()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 toIndex(position)); | 283 toIndex(position)); |
| 283 GeolocationInfo locationSettings = new GeolocationInfo(url, null, false) ; | 284 GeolocationInfo locationSettings = new GeolocationInfo(url, null, false) ; |
| 284 ContentSetting locationPermission = locationSettings.getContentSetting() ; | 285 ContentSetting locationPermission = locationSettings.getContentSetting() ; |
| 285 // Handle the case where the geoHeader being sent when no permission has been specified. | 286 // Handle the case where the geoHeader being sent when no permission has been specified. |
| 286 if (locationPermission == ContentSetting.ASK && checkGeoHeader) { | 287 if (locationPermission == ContentSetting.ASK && checkGeoHeader) { |
| 287 return GeolocationHeader.isGeoHeaderEnabledForUrl(mContext, url, fal se); | 288 return GeolocationHeader.isGeoHeaderEnabledForUrl(mContext, url, fal se); |
| 288 } | 289 } |
| 289 return locationPermission == ContentSetting.ALLOW; | 290 return locationPermission == ContentSetting.ALLOW; |
| 290 } | 291 } |
| 291 } | 292 } |
| OLD | NEW |